Character switching
This commit is contained in:
parent
7daa4fd078
commit
c6a470aeef
1 changed files with 41 additions and 1 deletions
42
main.c
42
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue