We has workie UI I things

This commit is contained in:
Jarkko Toivanen 2025-01-17 12:22:40 +02:00
parent c6a470aeef
commit 2224f85718
Signed by: jt
GPG key ID: 9151B109B73ECAD5
3 changed files with 31 additions and 41 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
kaari kaari
kaari-linux-i386
kaari-linux-amd64

View file

@ -1,4 +1,8 @@
build: main.c build: main.c
tcc -o kaari main.c tcc -o kaari main.c
build-linux-32: main.c
tcc -m32 -o kaari-linux-i386 main.c
build-linux-64: main.c
tcc -m64 -o kaari-linux-amd64 main.c
run: main.c run: main.c
tcc -run main.c tcc -run main.c

62
main.c
View file

@ -6,12 +6,13 @@
#define clear() printf("\033[H\033[J") #define clear() printf("\033[H\033[J")
#define gotoxy(x,y) printf("\033[%d;%dH", (y), (x)) #define gotoxy(x,y) printf("\033[%d;%dH", (y), (x))
char fonth = 8;
int getch(); int getch();
void enableRawMode(); void enableRawMode();
void disableRawMode(); void disableRawMode();
void drawWin(int fonth); void drawWin();
int askHeight(); int askHeight();
void limitCurrChar(); void resetCurPos();
char currchar = 'A'; char currchar = 'A';
char xpos=0, ypos=0; char xpos=0, ypos=0;
@ -19,15 +20,12 @@ char xpos=0, ypos=0;
struct termios orig_termios; struct termios orig_termios;
int main() { int main() {
int fonth = askHeight();
clear();
drawWin(fonth);
enableRawMode(); enableRawMode();
char c; char c;
limitCurrChar();
while(1) { while(1) {
drawWin();
c = getch(); c = getch();
// Q to exit // Q to exit
if (c == 'q') { if (c == 'q') {
@ -36,41 +34,40 @@ int main() {
// Handle arrows and stuff // Handle arrows and stuff
if (c == '[') { if (c == '[') {
c = getch(); c = getch();
if (c == '5') { // PageUP if (c == '6') { // PageUP
currchar++; if (currchar < 126) { currchar++; }
limitCurrChar();
continue; continue;
} }
if (c == '6') { // PageDOWN if (c == '5') { // PageDOWN
currchar--; if (currchar >32) { currchar--; }
limitCurrChar();
continue; continue;
} }
if (c == 'A') { if (c == 'A') {
printf("^"); if (ypos > 0) { ypos--; }
continue; continue;
} }
if (c == 'B') { if (c == 'B') {
printf("v"); if (ypos < fonth-1) { ypos++; }
continue; continue;
} }
if (c == 'C') { if (c == 'C') {
printf(">"); if (xpos < 8-1) { xpos++; }
continue; continue;
} }
if (c == 'D') { if (c == 'D') {
printf("<"); if (xpos > 0) { xpos--; }
continue; continue;
} }
} }
} }
disableRawMode(); disableRawMode();
clear();
return 0; return 0;
} }
void drawWin(int fonth) { void drawWin() {
clear(); clear();
printf("Kaari - Binarier font editor\r\n"); printf("Kaari - Binarier font editor\r\n");
printf("+--------+\r\n"); printf("+--------+\r\n");
@ -81,13 +78,19 @@ void drawWin(int fonth) {
for (int y=0; y<fonth; y++) { for (int y=0; y<fonth; y++) {
printf("| | "); printf("| | ");
for (int c=y*cperline+cstart; c<(y+1)*cperline+cstart && c<=cmax; c++) { for (int c=y*cperline+cstart; c<(y+1)*cperline+cstart && c<=cmax; c++) {
printf("%c ", c); if (c == currchar) {
printf("\033[7m%c\033[0m ", currchar);
} else {
printf("%c ", c);
}
} }
printf("\r\n"); printf("\r\n");
} }
printf("+--------+\r\nQ:Quit PgUP/DWN:Switch char\r\n"); printf("+--------+\r\nQ:Quit PgUP/DWN:Switch char\r\n");
resetCurPos();
return; return;
} }
@ -132,26 +135,7 @@ int getch() {
return ch; return ch;
} }
void limitCurrChar() { void resetCurPos() {
if (currchar < 32) { gotoxy(2+xpos, 3+ypos);
currchar = 32;
} else if (currchar > 126) {
currchar = 126;
}
gotoxy(12+currchar%16*2, 3+(currchar-32)/16);
printf("\033[7m%c", currchar);
gotoxy(12+(currchar-1)%16*2, 3+(currchar-1-32)/16);
printf("\033[0m%c", currchar-1);
gotoxy(12+(currchar+1)%16*2, 3+(currchar+1-32)/16);
printf("\033[0m%c", currchar+1);
gotoxy(12, 2);
printf("\033[0mEditing \"%c\" / %d / 0x%X", currchar, currchar, currchar);
gotoxy(0, 21);
return; return;
} }