терминал и клавиатуры указать.
ctrl+c - exit
space - paste icon
del - clen for space
c - all clear
left, up, down, right - #
-/+ - ... ... icons<... ...
30 x 10─ ━ │ ┃ ┄ ┅ ┆ ┇<┈ ┉ ┊ ┋ ┌ ┍ ┎
9479
#
┌╍┓
╎
║
// edicons.c
// victor00000 (c) 2018
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <termios.h>
#include <locale.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
// ~$ gcc edicons.c -o edicons -lpthread
// ~$ ./edicons
/* keyboard:
ctrl+c - exit
space - paste icon
del - clen for space
c - all clear
left, up, down, right - #
-/+ - ... ... icons<... ...
*/
int icn = 9484, icn_1;
int xw = 30, yh = 10;
int xy [30] [10];
int x = 0, y = 0;
struct termios old;
pthread_mutex_t mt;
int exit_A = 0;
pthread_t t;
int icn_v (){
int i,i1;
for (i=0;i<15;i++){
if (i == 15 / 2){
printf ("%lc<",icn+i);
i1 = icn + i;
}
else
printf ("%lc ",icn+i);
}
puts ("");
return i1;
}
void *pth_xy (void *a){
icn_1 = icn;
int exit_0 = 0;
int ix,iy;
int8_t bl = 0;
while (1){
system ("clear");
// puts ("AAAA");
icn_1 = icn_v ();
printf ("%-7d\n",icn_1);
for (iy=0;iy < yh ;iy++){
for (ix=0;ix < xw ;ix++){
if (x == ix && y == iy && bl == 1)
putchar ('#');
else
printf ("%lc",xy [ix] [iy]);
}
puts ("");
}
usleep (1000*100);
pthread_mutex_lock (&mt);
exit_0 = exit_A;
pthread_mutex_unlock (&mt);
if (exit_0 == 1) break;
bl ^= 1;
}
return 0;
}
void s(int a){
tcsetattr( fileno( stdin ),
TCSANOW, &old );
pthread_mutex_lock (&mt);
exit_A = 1;
pthread_mutex_unlock (&mt);
pthread_join (t,0);
exit (0);
}
void xy_clean (){
int ix,iy;
for (ix=0;ix < xw ;ix++)
for (iy=0;iy < yh ;iy++)
xy [ix] [iy] = L' ';
}
//====================m0
int main (){
signal(SIGINT, s);
setlocale (LC_ALL,getenv("LANG"));
xy_clean ();
pthread_create (&t,0,pth_xy,0);
// pthread_detach (t);
int8_t ki [ 3 ],kl = 0;
struct termios new;
tcgetattr( fileno( stdin ),&old );
new = old;
new.c_lflag &= (~ICANON & ~ECHO);
tcsetattr ( fileno ( stdin ),
TCSANOW, &new );
fd_set st;
char b;
// int b;
// int l;
struct timeval tv;
int res = 0;
while (1){
tv.tv_sec = 10;
tv.tv_usec = 0;
FD_ZERO( &st );
FD_SET (fileno( stdin ), &st );
res = select (
fileno( stdin ) + 1 ,
&st, NULL, NULL, &tv );
if (res > 0){
read ( fileno (stdin),&b,1 );
ki[kl] = b;
if ( ki[0] == 27 && ki[1] == 27 )break;
if (ki[0] == 27) kl++;
if (kl>2) kl = 0;
if (ki[0] == 27 && kl == 0){
// printf (" = %d %d %d\n",
// ki[0],ki[1],ki[2] );
if (ki[2] == 66)
if (y != yh - 1) y++;
if (ki[2] == 65)
if (y != 0) y--;
if (ki[2] == 68)
if (x != 0) x--;
if (ki[2] == 67)
if (x != xw - 1) x++;
}else{
if (ki[0] != 27){
if (ki[0] == 99 || ki[0] == 67 || ki[0] == 126 || ki[0] == 32 || ki[0] == 43 || ki[0] == 45){}
else{
printf (" = %d\n",b );
}}
if (ki[0] == 45) icn--;
if (ki[0] == 43) icn++;
if (ki[0] == 32)
xy [x] [y] = icn_1;
if (ki[0] == 126)
xy [x] [y] = L' ';
if (ki[0] == 67 || ki[0] == 99)
xy_clean ();
//================i1
}
}
}
// close (k);
tcsetattr( fileno( stdin ),
TCSANOW, &old );
pthread_mutex_lock (&mt);
exit_A = 1;
pthread_mutex_unlock (&mt);
pthread_join (t,0);
return 0;
}
Пользователь добавил сообщение 23 Сентября 2018, 23:58:42:
выход в авто сохранения.
icn_load() и icn_save().
// edicons.c
// victor00000 (c) 2018
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <termios.h>
#include <locale.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
// ~$ gcc edicons.c -o edicons -lpthread
// ~$ ./edicons
/* keyboard:
ctrl+c - exit
space - paste icon
del - clen for space
c - all clear
left, up, down, right - #
-/+ - ... ... icons<... ...
*/
int icn = 9484, icn_1;
int xw = 30, yh = 10;
int xy [30] [10];
int x = 0, y = 0;
struct termios old;
pthread_mutex_t mt;
int exit_A = 0;
pthread_t t;
//===================load
void icn_load (){
FILE *fl;
if (chdir (getenv("HOME")) ) {
perror ("HONE no dir");
exit (1);
}
fl = fopen (".icnsrc","r");
if (fl == 0){
//perror (".icnsrc");
//exit (1);
return;
}
fread (&icn,1,sizeof(int),fl);
fread (&x,1,sizeof(int),fl);
fread (&y,1,sizeof(int),fl);
fread (xy,1,
sizeof(int)*xw*yh,fl);
fclose (fl);
}
//===================save
void icn_save (){
FILE *fs;
if (chdir (getenv("HOME")) ) {
perror ("HONE no dir");
exit (1);
}
fs = fopen (".icnsrc","w");
if (fs == 0){
perror (".icnsrc");
exit (1);
}
fwrite (&icn,1,sizeof(int),fs);
fwrite (&x,1,sizeof(int),fs);
fwrite (&y,1,sizeof(int),fs);
fwrite (xy,1,
sizeof(int)*xw*yh,fs);
//================fs1
fclose (fs);
}
int icn_v (){
int i,i1;
for (i=0;i<15;i++){
if (i == 15 / 2){
printf ("%lc<",icn+i);
i1 = icn + i;
}
else
printf ("%lc ",icn+i);
}
puts ("");
return i1;
}
void *pth_xy (void *a){
icn_1 = icn;
int exit_0 = 0;
int ix,iy;
int8_t bl = 0;
while (1){
system ("clear");
// puts ("AAAA");
icn_1 = icn_v ();
printf ("%-7d\n",icn_1);
for (iy=0;iy < yh ;iy++){
for (ix=0;ix < xw ;ix++){
if (x == ix && y == iy && bl == 1)
putchar ('#');
else
printf ("%lc",xy [ix] [iy]);
}
puts ("");
}
usleep (1000*100);
pthread_mutex_lock (&mt);
exit_0 = exit_A;
pthread_mutex_unlock (&mt);
if (exit_0 == 1) break;
bl ^= 1;
}
return 0;
}
void s(int a){
tcsetattr( fileno( stdin ),
TCSANOW, &old );
pthread_mutex_lock (&mt);
exit_A = 1;
pthread_mutex_unlock (&mt);
pthread_join (t,0);
icn_save ();
exit (0);
}
void xy_clean (){
int ix,iy;
for (ix=0;ix < xw ;ix++)
for (iy=0;iy < yh ;iy++)
xy [ix] [iy] = L' ';
}
//====================m0
int main (){
signal(SIGINT, s);
setlocale (LC_ALL,getenv("LANG"));
xy_clean ();
icn_load ();
pthread_create (&t,0,pth_xy,0);
// pthread_detach (t);
int8_t ki [ 3 ],kl = 0;
struct termios new;
tcgetattr( fileno( stdin ),&old );
new = old;
new.c_lflag &= (~ICANON & ~ECHO);
tcsetattr ( fileno ( stdin ),
TCSANOW, &new );
fd_set st;
char b;
// int b;
// int l;
struct timeval tv;
int res = 0;
while (1){
tv.tv_sec = 10;
tv.tv_usec = 0;
FD_ZERO( &st );
FD_SET (fileno( stdin ), &st );
res = select (
fileno( stdin ) + 1 ,
&st, NULL, NULL, &tv );
if (res > 0){
read ( fileno (stdin),&b,1 );
ki[kl] = b;
if ( ki[0] == 27 && ki[1] == 27 )break;
if (ki[0] == 27) kl++;
if (kl>2) kl = 0;
if (ki[0] == 27 && kl == 0){
// printf (" = %d %d %d\n",
// ki[0],ki[1],ki[2] );
if (ki[2] == 66)
if (y != yh - 1) y++;
if (ki[2] == 65)
if (y != 0) y--;
if (ki[2] == 68)
if (x != 0) x--;
if (ki[2] == 67)
if (x != xw - 1) x++;
}else{
if (ki[0] != 27){
if (ki[0] == 99 || ki[0] == 67 || ki[0] == 126 || ki[0] == 32 || ki[0] == 43 || ki[0] == 45){}
else{
printf (" = %d\n",b );
}}
if (ki[0] == 45) icn--;
if (ki[0] == 43) icn++;
if (ki[0] == 32)
xy [x] [y] = icn_1;
if (ki[0] == 126)
xy [x] [y] = L' ';
if (ki[0] == 67 || ki[0] == 99)
xy_clean ();
//================i1
}
}
}
// close (k);
tcsetattr( fileno( stdin ),
TCSANOW, &old );
pthread_mutex_lock (&mt);
exit_A = 1;
pthread_mutex_unlock (&mt);
pthread_join (t,0);
icn_save ();
return 0;
}
http://paste.ubuntu.com/p/PmB8Sk7Y6g/