[Top][All Lists]

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

Ncurses + readline problem

From: Sergey I. Sharybin
Subject: Ncurses + readline problem
Date: Sun, 29 Mar 2009 17:38:42 +0600
User-agent: Thunderbird (X11/20080213)


I'm writting some console program using ncurses for interface. In this program I want to implement small subshell using readline for command prompt. I'm switching ncurses to shell mode and call the readline() function. After this I return ncurses to program mode. But after I called the readline() function I can't get correct terminal size through the LINES and COLS variables. The terminal's size before readline() is stored in this variables and this values isn't changes anyway after readline() function called.

Is it mine programming error or it is bug of ncurses or readline?

I attached small sample program to this letter.


With best regards, Sergey I. Sharybin

#include <ncursesw/ncurses.h>
#include <readline/readline.h>
#include <malloc.h>
#include <signal.h>

static int subshell = 0;

static void
sig_winch (int sig)
  if (subshell)

  endwin ();
  refresh ();
  printf ("%d %d\n", LINES, COLS);
  fflush (stdout);

main (int __argc, char **__argv)
  struct timespec timestruc;

  timestruc.tv_sec  = 0;
  timestruc.tv_nsec = 0.2 * 1000 * 1000;

  initscr ();

  signal (SIGWINCH, sig_winch);

  cbreak ();  /* take input chars one at a time, no wait for \n */
  noecho ();  /* don't echo input */
  nodelay (stdscr, TRUE);
  start_color ();

  for (;;)
      wchar_t ch;
      wget_wch (stdscr, &ch);

     if (ch == 'q')
     else if (ch == 's')
         char *buf;

         subshell = 1;

         def_prog_mode ();
         nodelay (stdscr, FALSE);
         endwin ();

         buf = readline (">>> ");

         if (buf)
             free (buf);

         refresh ();
         nodelay (stdscr, TRUE);

         subshell = 0;

      nanosleep (&timestruc, 0);

  endwin ();

  return 0;

reply via email to

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