Skip to contentSkip to conversation

Fix monitor console in curses mode

PATCH In review Ryan Harper 2 participants 5 messages Aug 22, 2008 KVM

lore
Share & tools
lore
#0 lore raw

cover Fix monitor console in curses mode

The current curses code doesn't set the initial monitor text console to the size of the terminal and fails to adjust properly after a resize. The attach patches create the initial console based on the size of the terminal instead of defaulting to 80x25, and also hook ensure that text_console_resize events adjust the Textconsole display area so they stay the same size as the curses display. The result is that we no longer see broken output like:

QEMU 0.9.1 monitor - type 'help' for more information

                    (qemu)
                                            (qemu)
                                                                (qemu)

and you can resize your terminal window and the monitor and serial text consoles adjust properly as well.

The second patch is a trivial typo fix in the comments in console.c

Comments welcome since I'm new to both curses and qemu console code.

#1 lore raw

PATCH 1/2 Fix text console size/resize when using curses

The current console output is broken in curses mode size the default starting size might not match the launching terminal size. Change initial size to be based on the terminal. Also, resize events fail to ensure that both the text console and curses display areas are the same size; this causes broken output like:

QEMU 0.9.1 monitor - type 'help' for more information

                    (qemu)
                                            (qemu)
                                                                (qemu)

To fix this, ensure that the display width and the text area width are sync for text consoles on refresh; also force a resize event whenever we invalidate the text console.

console.c +5 -0
index 1c94980..89bdc52 100644
@@ -608,6 +608,9 @@ static void console_refresh(TextConsole *s)
         s->text_y[0] = 0;
         s->text_x[1] = s->width - 1;
         s->text_y[1] = s->height - 1;
+        /* ensure that textconsole area is the same size as the display */
+        s->g_width = s->ds->width;
+        s->g_height = s->ds->height;
         s->cursor_invalidate = 1;
         return;
     }
@@ -1158,6 +1161,8 @@ static void text_console_invalidate(void *opaque)
     TextConsole *s = (TextConsole *) opaque;
 
     console_refresh(s);
+    /* resize if needed */
+    text_console_resize(s);
 }
 
 static void text_console_update(void *opaque, console_ch_t *chardata)
curses.c +4 -4
index d09eff2..a8972f4 100644
@@ -362,8 +362,8 @@ void curses_display_init(DisplayState *ds, int full_screen)
     ds->data = (void *) screen;
     ds->linesize = 0;
     ds->depth = 0;
-    ds->width = 640;
-    ds->height = 400;
+    ds->width = COLS * FONT_WIDTH;
+    ds->height = LINES * FONT_HEIGHT;
     ds->dpy_update = curses_update;
     ds->dpy_resize = curses_resize;
     ds->dpy_refresh = curses_refresh;
@@ -371,6 +371,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
 
     invalidate = 1;
 
-    /* Standard VGA initial text mode dimensions */
-    curses_resize(ds, 80, 25);
+    /* setup up initial display size based on terminal settings */
+    curses_resize(ds, COLS, LINES);
 }
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] Fix text console size/resize when using curses

2008/8/22 Ryan Harper <[email protected]>:

Quoted 56 lines

The current console output is broken in curses mode size the default starting size might not match the launching terminal size. Change initial size to be based on the terminal. Also, resize events fail to ensure that both the text console and curses display areas are the same size; this causes broken output like:

QEMU 0.9.1 monitor - type 'help' for more information

                   (qemu)
                                           (qemu)
                                                               (qemu)

To fix this, ensure that the display width and the text area width are sync for text consoles on refresh; also force a resize event whenever we invalidate the text console.

console.c +5 -0
index 1c94980..89bdc52 100644
@@ -608,6 +608,9 @@ static void console_refresh(TextConsole *s)
        s->text_y[0] = 0;
        s->text_x[1] = s->width - 1;
        s->text_y[1] = s->height - 1;
+        /* ensure that textconsole area is the same size as the display */
+        s->g_width = s->ds->width;
+        s->g_height = s->ds->height;
        s->cursor_invalidate = 1;
        return;
    }
@@ -1158,6 +1161,8 @@ static void text_console_invalidate(void *opaque)
    TextConsole *s = (TextConsole *) opaque;
 
    console_refresh(s);
+    /* resize if needed */
+    text_console_resize(s);
 }
 
 static void text_console_update(void *opaque, console_ch_t *chardata)
curses.c +2 -2
index d09eff2..a8972f4 100644
@@ -362,8 +362,8 @@ void curses_display_init(DisplayState *ds, int full_screen)
    ds->data = (void *) screen;
    ds->linesize = 0;
    ds->depth = 0;
-    ds->width = 640;
-    ds->height = 400;
+    ds->width = COLS * FONT_WIDTH;
+    ds->height = LINES * FONT_HEIGHT;
    ds->dpy_update = curses_update;
    ds->dpy_resize = curses_resize;
    ds->dpy_refresh = curses_refresh;

curses.c void curses_display_init(DisplayState *ds, int full_screen) · line 375

Quoted 7 lines
curses.c +2 -2
@@ -371,6 +371,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
 
    invalidate = 1;
 
-    /* Standard VGA initial text mode dimensions */
-    curses_resize(ds, 80, 25);
+    /* setup up initial display size based on terminal settings */
+    curses_resize(ds, COLS, LINES);

These two changes in curses.c don't look ok. ds->width/height and the curses_resize() parameters are not supposed to be the host terminal size, they're just the default settings for the virtual display size (same way as sdl.c sets 640x400 at start regardless of the host, and likely the bios will force the resize anyway). The host terminal dimensions are later taken into account in curses_calc_pad to ensure correct display.
I can't comment on the console.c changes at the moment.

Cheers

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] Fix text console size/resize when using curses

Quoted 60 lines · andrzej zaborowski

2008/8/22 Ryan Harper <[email protected]>:

Quoted 59 lines

The current console output is broken in curses mode size the default starting size might not match the launching terminal size. Change initial size to be based on the terminal. Also, resize events fail to ensure that both the text console and curses display areas are the same size; this causes broken output like:

QEMU 0.9.1 monitor - type 'help' for more information

                   (qemu)
                                           (qemu)
                                                               (qemu)

To fix this, ensure that the display width and the text area width are sync for text consoles on refresh; also force a resize event whenever we invalidate the text console.

console.c +5 -0
index 1c94980..89bdc52 100644
@@ -608,6 +608,9 @@ static void console_refresh(TextConsole *s)
        s->text_y[0] = 0;
        s->text_x[1] = s->width - 1;
        s->text_y[1] = s->height - 1;
+        /* ensure that textconsole area is the same size as the display */
+        s->g_width = s->ds->width;
+        s->g_height = s->ds->height;
        s->cursor_invalidate = 1;
        return;
    }
@@ -1158,6 +1161,8 @@ static void text_console_invalidate(void *opaque)
    TextConsole *s = (TextConsole *) opaque;
 
    console_refresh(s);
+    /* resize if needed */
+    text_console_resize(s);
 }
 
 static void text_console_update(void *opaque, console_ch_t *chardata)
curses.c +2 -2
index d09eff2..a8972f4 100644
@@ -362,8 +362,8 @@ void curses_display_init(DisplayState *ds, int full_screen)
    ds->data = (void *) screen;
    ds->linesize = 0;
    ds->depth = 0;
-    ds->width = 640;
-    ds->height = 400;
+    ds->width = COLS * FONT_WIDTH;
+    ds->height = LINES * FONT_HEIGHT;
    ds->dpy_update = curses_update;
    ds->dpy_resize = curses_resize;
    ds->dpy_refresh = curses_refresh;
@@ -371,6 +371,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
 
    invalidate = 1;
 
Quoted 12 lines

curses.c void curses_display_init(DisplayState *ds, int full_screen) · line 375

Quoted 4 lines
curses.c +2 -2
-    /* Standard VGA initial text mode dimensions */
-    curses_resize(ds, 80, 25);
+    /* setup up initial display size based on terminal settings */
+    curses_resize(ds, COLS, LINES);

These two changes in curses.c don't look ok. ds->width/height and the curses_resize() parameters are not supposed to be the host terminal size, they're just the default settings for the virtual display size (same way as sdl.c sets 640x400 at start regardless of the host, and likely the bios will force the resize anyway). The host terminal dimensions are later taken into account in curses_calc_pad to ensure correct display.

Hrm, indeed. I had initially included that because without it the first display of the monitor wasn't correct. Pulling those changes out, that doesn't seem to be needed any more.

Quoted 1 line

I can't comment on the console.c changes at the moment.

I'll await comments on console.c and resend without the above two superflous changes.

Signature · 5 lines
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
[email protected]
#4 lore raw

PATCH 2/2 Fix typo in console.c comment

In reply to Ryan Harper
console.c +1 -1
index 89bdc52..c7a5a80 100644
@@ -172,7 +172,7 @@ void vga_hw_screen_dump(const char *filename)
     previous_active_console = active_console;
     active_console = consoles[0];
     /* There is currently no way of specifying which screen we want to dump,
-       so always dump the dirst one.  */
+       so always dump the first one.  */
     if (consoles[0]->hw_screen_dump)
         consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
     active_console = previous_active_console;