Skip to contentSkip to conversation

ncurses: resize console if required

PATCH In review Carlo Marcelo Arenas Belon 5 participants 9 messages Apr 28, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ncurses: resize console if required

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Carlo

---

curses.c +5 -0
Index: curses.c
===================================================================
@@ -367,6 +367,11 @@
 
     invalidate = 1;
 
+    /* check size of console and try to adjust if needed */
+    getmaxyx(stdscr, gheight, gwidth);
+    if ((gwidth != 80) || (gheight != 25)) {
+	printf("\033[8;25;80t");
+    }
     /* Standard VGA initial text mode dimensions */
     curses_resize(ds, 80, 25);
 }
#1 lore raw

Hello,

curses.c line 374

Quoted 9 lines · Carlo Marcelo Arenas Belon, le Sun 27 Apr 2008 22:54:45 -0500, a écrit :

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

curses.c +5 -0
+    /* check size of console and try to adjust if needed */
+    getmaxyx(stdscr, gheight, gwidth);
+    if ((gwidth != 80) || (gheight != 25)) {
+	printf("\033[8;25;80t");
+    }

You can not just spit out escape sequences like this without know the kind of terminal you're in, you know :)

At least check the TERM environment variable for those kind you know support it. Also, this should probably go inside the curses_resize() function, so that when the guest resizes to e.g. 80x50, the xterm window gets resized too.

Samuel

#2 lore raw
Quoted 7 lines · Samuel Thibault

Hello,

Quoted 3 lines · Carlo Marcelo Arenas Belon, le Sun 27 Apr 2008 22:54:45 -0500, a écrit :

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Quoted 8 lines

curses.c line 374

Quoted 5 lines
curses.c +5 -0
+    /* check size of console and try to adjust if needed */
+    getmaxyx(stdscr, gheight, gwidth);
+    if ((gwidth != 80) || (gheight != 25)) {
+	printf("\033[8;25;80t");
+    }

You can not just spit out escape sequences like this without know the kind of terminal you're in, you know :)

my original patch was checking the TERM variable for xterm or rxvt but since CSI Window manipulation comes from dtterm I would expect most terminal emulators to support that, do you have one that does not?

in the case of xterm with allowWindowOps = false the escape string gets just ignored with no visible output, so expected the same from a terminal that doesn't support it, but since it seems all the terminals I have access to do, wasn't able to test that.

Quoted 4 lines

At least check the TERM environment variable for those kind you know support it. Also, this should probably go inside the curses_resize() function, so that when the guest resizes to e.g. 80x50, the xterm window gets resized too.

from my tests, while booting a linux guest, curses_resize will be called with a 66 x 3 geometry at least once, and a first attempt to make the guest use a resized console of 80x50 didn't reflect correctly in the curses side either so I settled for this different implementation as a starting point, and that solves the problem with default sized xterm used as a curses console.

my intention with this patch was to propose a simple solution to this problem and hopefully get someone else with more experience in curses and terminal emulations intrigued enough to give it a more complete spin.

Carlo

#3 lore raw
Quoted 4 lines · Carlo Marcelo Arenas Belon, le Mon 28 Apr 2008 12:56:31 -0500, a écrit :
Quoted 3 lines · Samuel Thibault

Hello,

Carlo Marcelo Arenas Belon, le Sun 27 Apr 2008 22:54:45 -0500, a écrit :

Quoted 8 lines
Quoted 4 lines

curses.c line 373

Quoted 1 line
curses.c +1 -0
+	printf("\033[8;25;80t");

You can not just spit out escape sequences like this without know the kind of terminal you're in, you know :)

my original patch was checking the TERM variable for xterm or rxvt but since CSI Window manipulation comes from dtterm I would expect most terminal emulators to support that, do you have one that does not?

My good old _real_ ampex232 TTY most probably doesn't (I can't check right now).

Quoted 3 lines

in the case of xterm with allowWindowOps = false the escape string gets just ignored with no visible output, so expected the same from a terminal that doesn't support it,

If it supports CSI sequences.

Quoted 7 lines
Quoted 4 lines

At least check the TERM environment variable for those kind you know support it. Also, this should probably go inside the curses_resize() function, so that when the guest resizes to e.g. 80x50, the xterm window gets resized too.

from my tests, while booting a linux guest, curses_resize will be called with a 66 x 3 geometry at least once,

When it goes in graphical mode, yes.

Quoted 2 lines

and a first attempt to make the guest use a
resized console of 80x50 didn't reflect correctly in the curses side either

Works fine for me.

Quoted 3 lines

my intention with this patch was to propose a simple solution to this problem and hopefully get someone else with more experience in curses and terminal emulations intrigued enough to give it a more complete spin.

Ok.

Samuel

#4 lore raw
In reply to Carlo Marcelo Arenas Belon
Quoted 3 lines · Carlo Marcelo Arenas Belon

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Sounds like this should be specific to the PC/VGA emulation.

Thiemo

Quoted 20 lines

Carlo

---
Index: curses.c
===================================================================

curses.c +5 -0
@@ -367,6 +367,11 @@
 
     invalidate = 1;
 
+    /* check size of console and try to adjust if needed */
+    getmaxyx(stdscr, gheight, gwidth);
+    if ((gwidth != 80) || (gheight != 25)) {
+	printf("\033[8;25;80t");
+    }
     /* Standard VGA initial text mode dimensions */
     curses_resize(ds, 80, 25);
 }
#5 lore raw
Quoted 6 lines · Thiemo Seufer
Quoted 3 lines · Carlo Marcelo Arenas Belon

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Sounds like this should be specific to the PC/VGA emulation.

not sure what you mean, but the curses.c emulation assumes (and is hardcoded) to a 80x25 console anyway.

this patch only checks the window size of the console that is being used and sends it an escape command to change its size to what the curses console will use so that they match; otherwise if starting qemu from an 80x24 xterm with -curses you won't be able to see the last line of the console until the window is resized.

Carlo

Quoted 18 lines
Quoted 18 lines

---
Index: curses.c
===================================================================

curses.c +5 -0
@@ -367,6 +367,11 @@
 
     invalidate = 1;
 
+    /* check size of console and try to adjust if needed */
+    getmaxyx(stdscr, gheight, gwidth);
+    if ((gwidth != 80) || (gheight != 25)) {
+        printf("\033[8;25;80t");
+    }
     /* Standard VGA initial text mode dimensions */
     curses_resize(ds, 80, 25);
 }
#6 lore raw
Quoted 10 lines · Carlo Marcelo Arenas Belon, le Mon 28 Apr 2008 12:31:13 -0500, a écrit :
Quoted 6 lines · Thiemo Seufer
Quoted 3 lines · Carlo Marcelo Arenas Belon

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Sounds like this should be specific to the PC/VGA emulation.

not sure what you mean, but the curses.c emulation assumes (and is hardcoded) to a 80x25 console anyway.

Initial, yes. But it gets initialized early to the platform value by the firmware (e.g. the VGA BIOS, but could be whatever else).

Samuel

#7 lore raw
In reply to Carlo Marcelo Arenas Belon
Quoted 11 lines · Carlo Marcelo Arenas Belon
Quoted 6 lines · Thiemo Seufer
Quoted 3 lines · Carlo Marcelo Arenas Belon

The following patch instructs qemu to print an escape command to resize the curses console to 80x25 if detected to have a different geometry (xterm and friends use 80x24 by default).

Sounds like this should be specific to the PC/VGA emulation.

not sure what you mean, but the curses.c emulation assumes (and is hardcoded)
to a 80x25 console anyway.

It's only this way because SDL uses 640x400, but it can change when the vga starts living. For example the text mode ms windows installer (80x43 or something) worked fine for me with -curses.

Quoted 6 lines

this patch only checks the window size of the console that is being used and sends it an escape command to change its size to what the curses console will use so that they match; otherwise if starting qemu from an 80x24 xterm with -curses you won't be able to see the last line of the console until the window is resized.

To be honest I wasn't aware that there's a sequence to request terminal size change. "man console_codes" on my system doesn't list this sequence and also it doesn't seem to have any effect in gnome-terminal. This backend however is the curses backend, not terminal backend and even if the sequence worked, we should only use what curses can provide (this means that we don't even need a unix terminal). It seems that curses generally wants programs to be aware of the terminal size and conform, rather than have any say. So that would be a policy change also.

Regards

Signature · 2 lines
Please do not print this email unless absolutely necessary. Spread
environmental awareness.
#8 lore raw
Quoted 2 lines · andrzej zaborowski, le Mon 28 Apr 2008 21:17:56 +0200, a écrit :

we should only use what curses can provide (this means that we don't even need a unix terminal).

Curses doesn't provide this in the terminfo database.

Quoted 3 lines

It seems that curses generally wants programs to be aware of the terminal size and conform, rather than have any say. So that would be a policy change also.

Well, the resizing sequence will trigger a SIGWINCH, which will make ncurses adapt to the new size, so it's more a negociation.

Samuel