bug-ncurses
[Top][All Lists]
Advanced

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

Re: Ncurses + readline problem


From: Thomas Dickey
Subject: Re: Ncurses + readline problem
Date: Sun, 29 Mar 2009 11:58:01 -0400
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Mar 29, 2009 at 05:38:42PM +0600, Sergey I. Sharybin wrote:
> Hi,
>
> 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?

the former (see below)

>
> I attached small sample program to this letter.
>
> Thanks,
>
> -- 
> 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)
>     {
>       return;
>     }

the following are unsafe to do in a signal handler.

> 
>   endwin ();
>   refresh ();
>   printf ("%d %d\n", LINES, COLS);
>   fflush (stdout);
> }
> 
> int
> main (int __argc, char **__argv)
> {
>   struct timespec timestruc;
> 
>   timestruc.tv_sec  = 0;
>   timestruc.tv_nsec = 0.2 * 1000 * 1000;
> 
>   initscr ();

ncurses has setup a SIGWINCH handler.

> 
>   signal (SIGWINCH, sig_winch);

this overrides ncurses's SIGWINCH handler, so it cannot know if the
screensize changed (and it won't update LINES and COLS).
 
>   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')
>        {
>          break;
>        }
>      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;
> }

> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-ncurses


-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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