I currently have readline reading directly from the TTY. I think this
will get messy, so I want to handle input and other terminal
operations exclusively with ncurses (using e.g. getch()) and forward
the appropriate characters to readline. Is the following an okay
approach? Will it correctly handle e.g. timeouts?

static char input;
static bool input_avail = false;

static int cli_getc(FILE *f) {
    input_avail = false;

    return input;
}

static int cli_input_avail(void) {
    return input_avail;
}

static void init_readline() {
    rl_prep_term_function = NULL;
    rl_deprep_term_function = NULL;
    rl_getc_function = cli_getc;
    rl_input_available_hook = cli_input_avail;

    ...
}

static void handle_input() {
    ...
    input = getch();
    ...
    input_avail = true;
    rl_callback_read_char();
}

Things seem to work if cli_input_avail() is made to always return
'false' too. Is that safe in general?

/Ulf

_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to