I'm trying to simulate the history of a shell like script. The first step (at least from what I think) is to make it recognise the up or down arrows. Let me show you the code first:
string readSequence() {
int c;
string currLine;
do {
if (getchar() == '\033') { // if the first value is esc
getchar(); // skip the [
c = getchar(); // get the real value
if(c == 'A') // the real value
cout << "up";
if(c == 'B')
cout << "down";
}
} while(c != EOF || c != '\n');
}
Whenever I run this in the command line, if I press up down up down for instance, it will print ^[[A^[[B^[[A^[[B, and after I press enter it will print updownupdown. I'm trying to make it print up or down as soon as the user presses up or down, and also make it not to print those ^[[A or ^[[B things.
Also, if you got any suggestions on how to do this in another way, please do share. Thanks in advance!