I'm trying to make arrow keys move between characters in a single line (left + right) and between commands from history (up + down) for a custom shell (semester project).
at this point when hitting one of the arrows ^[[A, ^[[B, ^[[C or ^[[D is displayed and after hitting enter I recognize that one of them is hit using:
char a = getchar();
if (a == '\033') {
getchar();
int ch2 = getchar();
switch(ch2){
case 'A':
printf("UP\n");
break;
case 'B':
printf("DOWN\n");
break;
case 'D':
printf("LEFT\n");
break;
case 'C':
printf("RIGHT\n");
break;
default:
printf("SOME OTHER SCROLL KEY PRESSED: %d %d\n", a, ch2);
break;
}
}
What I want to get is that as soon as a I hit one of the arrows the action happens without displaying anything.