I'm trying to get the string representing the arrow key up from the termcap database. Using the following:
char *buffer = malloc(2048);
tgetent(buffer, getenv("TERM")); //TERM = xterm-256color
char *key_up = tgetstr("ku", &buffer); // gives me \EOA
ku
String of input sent by typing the up-arrow key.
The problem is the arrow key up is actually passed as \E[A
when typing into the program. It's also passed like this to cat
. I tried with different terminal emulators and shells and they all passed it the same way.
So I decided to hardcode this value for the key instead of using the ku
value, and it works, but doesn't feel right.
Am I missing something here? How can I programmatically get the right ku
value?