From c6a470aeef767e5f357aee7cf1d9d7ad5a19caf3 Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Fri, 17 Jan 2025 06:09:31 +0200 Subject: [PATCH] Character switching --- main.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 72e5ede..2a872bb 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,10 @@ void enableRawMode(); void disableRawMode(); void drawWin(int fonth); int askHeight(); +void limitCurrChar(); + +char currchar = 'A'; +char xpos=0, ypos=0; struct termios orig_termios; @@ -22,6 +26,7 @@ int main() { enableRawMode(); char c; + limitCurrChar(); while(1) { c = getch(); // Q to exit @@ -31,6 +36,17 @@ int main() { // Handle arrows and stuff if (c == '[') { c = getch(); + if (c == '5') { // PageUP + currchar++; + limitCurrChar(); + continue; + } + if (c == '6') { // PageDOWN + currchar--; + limitCurrChar(); + continue; + } + if (c == 'A') { printf("^"); continue; @@ -70,7 +86,7 @@ void drawWin(int fonth) { printf("\r\n"); } - printf("+--------+\r\nQ:Quit"); + printf("+--------+\r\nQ:Quit PgUP/DWN:Switch char\r\n"); return; } @@ -115,3 +131,27 @@ int getch() { 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; +}