I have a small test program as follow trying to get a two window ncurses
screen to work with readline()
.
When I call readline()
, the typing works, but I can't see it. Somehow the echoing is lost. With the getch()
(if you don't #define READLINE
) then the typing appears at the wrong place.
Is there a way to get readline()
to work along ncurse
?
#include <curses.h>
#include <readline/readline.h>
#define READLINE
int main(int argc, char *argv[])
{
WINDOW * main_win = initscr();
int screen_width(1), screen_height(1);
getmaxyx(main_win, screen_height, screen_width);
wborder(main_win, 0, 0, 0, 0, 0, 0, 0, 0);
mvwaddch(main_win, screen_height - 6, 0, ACS_LTEE);
mvwhline(main_win, screen_height - 6, 1, ACS_HLINE, screen_width - 2);
mvwaddch(main_win, screen_height - 6, screen_width - 1, ACS_RTEE);
mvwprintw(main_win, 0, 2, " Output Window ");
mvwprintw(main_win, screen_height - 6, 2, " Input Window ");
wrefresh(main_win);
WINDOW * win0 = newwin(screen_height - 8, screen_width - 2, 1, 1);
WINDOW * win1 = newwin(4, screen_width - 2, screen_height - 5, 1);
wrefresh(win0);
wrefresh(win1);
scrollok(win0, TRUE);
scrollok(win1, TRUE);
for(;;)
{
mvwprintw(win1, 3, 0, "tcp> ");
wrefresh(win1);
#ifndef READLINE
char c(getch());
if(c == '\n')
{
scroll(win1);
}
#else
char * l(readline(""));
char c(*l);
if(c == '\0')
{
break;
}
scroll(win1);
#endif
if(c == 'q')
{
break;
}
}
endwin();
return 0;
}
// vim: ts=4 sw=4 et