#include #include #include #include #define clear() printf("\033[H\033[J") #define gotoxy(x,y) printf("\033[%d;%dH", (y), (x)) char fonth = 8; int getch(); void enableRawMode(); void disableRawMode(); void drawWin(); int askHeight(); void resetCurPos(); char currchar = 'A'; char xpos=0, ypos=0; struct termios orig_termios; int main() { clear(); enableRawMode(); char c; while(1) { drawWin(); c = getch(); // Q to exit if (c == 'q') { break; } // Handle arrows and stuff if (c == '[') { c = getch(); if (c == '6') { // PageUP if (currchar < 126) { currchar++; } continue; } if (c == '5') { // PageDOWN if (currchar >32) { currchar--; } continue; } if (c == 'A') { if (ypos > 0) { ypos--; } continue; } if (c == 'B') { if (ypos < fonth-1) { ypos++; } continue; } if (c == 'C') { if (xpos < 8-1) { xpos++; } continue; } if (c == 'D') { if (xpos > 0) { xpos--; } continue; } } } disableRawMode(); clear(); return 0; } void drawWin() { //clear(); gotoxy(1, 1); printf("Kaari - Binarier font editor\r\n"); printf("+--------+ Char \"%c\" / %d / 0x%X \r\n", currchar, currchar, currchar); int cstart=32; int cperline=16; int cmax=126; for (int y=0; y 16) { printf("This should be 8 - 16.\r\n"); return askHeight(); } return fonth; } void disableRawMode() { tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); } void enableRawMode() { tcgetattr(STDIN_FILENO, &orig_termios); atexit(disableRawMode); struct termios raw = orig_termios; raw.c_lflag &= ~(ECHO | ICANON); tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); } int getch() { struct termios oldt, newt; int ch; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } void resetCurPos() { gotoxy(2+xpos, 3+ypos); return; }