bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-readline] Forwarding input from ncurses to readline


From: Ulf Magnusson
Subject: [Bug-readline] Forwarding input from ncurses to readline
Date: Tue, 17 Feb 2015 14:20:59 +0100

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]