I am trying to emulate a user, pressing such special keys as <Left Arrow>
, <Backspace>
, <Delete>
and so on. I heard that curses/terminfo might help to do that in terminal-agnostic way, but when i try (with following code) to print first string "text" and then emmit a key_left
sequence, i am not getting a (with '|'
as cursor) "tex|t"
, but rather "textD|"
. Why? How to do that properly?
#include <term.h>
#include <stdio.h>
static void putf(const char *name) {
putp(name);
fflush(stdout);
}
int main(int argc, char **argv) {
setupterm((char*)0, 1, (int*)0);
printf("text");
fflush(stdout);
putf(key_left);
// hang up until user input
fgetc(stdin);
return 0;
}
Please note, while i am okay with using curses, ncurses is unacceptable in my use-case.
Also, note that i don't want to use something like initscr()
, replacing current terminal screen with blank one, it is not a desired behavior.