curses: resize terminal to fit console size
PATCH v2 1/1 curses: resize terminal to fit console size
The following patch, sends a resize escape character to the terminal used when running under curses to try to change its geometry to match the console size (as it is done with SDL).
As suggested, I'd added a check for the type of terminal used (currently only blacklisting "linux", eventhough from my tests it was just ignoring the escape sequence) which will need to be expanded to all known terminals which don't support this sequence. As suggested as well, I'd moved the resizing to the resize function so that it will be also called if the VGA mode is changed.
Carlo
curses.c +10 -0
@@ -39,6 +39,7 @@static console_ch_t screen[160 *100 ];static WINDOW *screenpad =NULL ; +static int term_resizable =1 ;static int width, height, gwidth, gheight, invalidate;static int px, py, sminx, sminy, smaxx, smaxy;
@@ -98,6 +99,9 @@if (w == gwidth && h == gheight)return ; +if (term_resizable && !is_graphic_console ()) +printf ("\033[8;%d;%dt" , h, w); + gwidth = w; gheight = h;
@@ -334,6 +338,7 @@void curses_display_init (DisplayState *ds,int full_screen) { +const char *term;#ifndef _WIN32if (!isatty (1 )) {fprintf (stderr,"We need a terminal output\n" );
@@ -367,6 +372,11 @@ invalidate =1 ; +/* check type of console and if it can be resized */ + term =getenv ("TERM" ); +if (strcmp (term,"linux" ) ==0 ) { + term_resizable =0 ; + }/* Standard VGA initial text mode dimensions */ curses_resize (ds,80 ,25 ); }
curses.c line 379
Quoted 9 lines · Carlo Marcelo Arenas Belon, le Thu 01 May 2008 02:52:40 -0500, a écrit :
curses.c +5
-0@@ -367,6 +372,11 @@ invalidate =1 ; +/* check type of console and if it can be resized */ + term =getenv ("TERM" ); +if (strcmp (term,"linux" ) ==0 ) { + term_resizable =0 ; + }
That should be the converse, i.e. check for the terminals you _know_ support it: rxvt*, xterm* at least. There are far more ttys (I mean also _real_ terminals, not only xterms) that don't support it than ttys that do.
Samuel