Character switching

This commit is contained in:
Jarkko Toivanen 2025-01-17 06:09:31 +02:00
parent 7daa4fd078
commit c6a470aeef
Signed by: jt
GPG key ID: 9151B109B73ECAD5

42
main.c
View file

@ -11,6 +11,10 @@ void enableRawMode();
void disableRawMode(); void disableRawMode();
void drawWin(int fonth); void drawWin(int fonth);
int askHeight(); int askHeight();
void limitCurrChar();
char currchar = 'A';
char xpos=0, ypos=0;
struct termios orig_termios; struct termios orig_termios;
@ -22,6 +26,7 @@ int main() {
enableRawMode(); enableRawMode();
char c; char c;
limitCurrChar();
while(1) { while(1) {
c = getch(); c = getch();
// Q to exit // Q to exit
@ -31,6 +36,17 @@ int main() {
// Handle arrows and stuff // Handle arrows and stuff
if (c == '[') { if (c == '[') {
c = getch(); c = getch();
if (c == '5') { // PageUP
currchar++;
limitCurrChar();
continue;
}
if (c == '6') { // PageDOWN
currchar--;
limitCurrChar();
continue;
}
if (c == 'A') { if (c == 'A') {
printf("^"); printf("^");
continue; continue;
@ -70,7 +86,7 @@ void drawWin(int fonth) {
printf("\r\n"); printf("\r\n");
} }
printf("+--------+\r\nQ:Quit"); printf("+--------+\r\nQ:Quit PgUP/DWN:Switch char\r\n");
return; return;
} }
@ -115,3 +131,27 @@ int getch() {
return ch; return ch;
} }
void limitCurrChar() {
if (currchar < 32) {
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;
}