Skip to contentSkip to conversation

ui/console: add escape sequence \e[5,6n

PATCH Superseded Ren Kimura 2 participants 3 messages Mar 6, 2016 – Mar 8, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ren Kimura

author
#0 lore raw

PATCH v2 1/1 ui/console: add escape sequence \e[5,6n

Add support of escape sequence "\e[5n" and "\e[6n" to console. "\e[5n" reports status of console and it always succeed in virtual console.
"\e[6n" reports now cursor position in console.

---
 ui/console.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
ui/console.c +33 -2
index ae61382..537a509 100644
@@ -757,6 +757,25 @@ static void console_clear_xy(QemuConsole *s, int x, int y)
     update_xy(s, x, y);
 }
 
+static void console_respond_str(QemuConsole *s, const char *buf)
+{
+    TextCell *c;
+    int y1;
+    while (*buf) {
+        if (s->x >= s->width) {
+            s->x = 0;
+            console_put_lf(s);
+        }
+        y1 = (s->y_base + s->y) % s->total_height;
+        c = &s->cells[y1 * s->width + s->x];
+        c->ch = *buf;
+        c->t_attrib = s->t_attrib;
+        update_xy(s, s->x, s->y);
+        s->x++;
+        buf++;
+    }
+}
+
 /* set cursor, checking bounds */
 static void set_cursor(QemuConsole *s, int x, int y)
 {
@@ -782,6 +801,7 @@ static void console_putchar(QemuConsole *s, int ch)
     TextCell *c;
     int y1, i;
     int x, y;
+    char response[40];
 
     switch(s->state) {
     case TTY_STATE_NORM:
@@ -956,8 +976,19 @@ static void console_putchar(QemuConsole *s, int ch)
                 console_handle_escape(s);
                 break;
             case 'n':
-                /* report cursor position */
-                /* TODO: send ESC[row;colR */
+                switch (s->esc_params[0]) {
+                case 5:
+                    /* report console status (always succeed)*/
+                    console_respond_str(s, "\033[0n");
+                    break;
+                case 6:
+                    /* report cursor position */
+                    sprintf(response, "\033[%d;%dR",
+                           (s->y_base + s->y) % s->total_height + 1,
+                            s->x + 1);
+                    console_respond_str(s, response);
+                    break;
+                }
                 break;
             case 's':
                 /* save cursor position */
Signature · 1 line
2.5.0
#1 lore raw

Re: [Qemu-devel] [PATCH v2] ui/console: add escape sequence \e[5, 6n

Quoted 6 lines
ui/console.c +5 -0
+static void console_respond_str(QemuConsole *s, const char *buf)
+{
+    TextCell *c;
+    int y1;
+    while (*buf) {
 

ui/console.c static void console_clear_xy(QemuConsole *s, int x, int y) · line 774

Quoted 10 lines
ui/console.c +10 -0
+        if (s->x >= s->width) {
+            s->x = 0;
+            console_put_lf(s);
+        }
+        y1 = (s->y_base + s->y) % s->total_height;
+        c = &s->cells[y1 * s->width + s->x];
+        c->ch = *buf;
+        c->t_attrib = s->t_attrib;
+        update_xy(s, s->x, s->y);
+        s->x++;

I think you should just call console_putchar() here instead of cut +pasting that code block.

If that doesn't work for some reason move the code block to a new function which can be called from both console_putchar() and console_respond_str().

thanks,
Gerd

author
#2 lore raw

Re: [Qemu-devel] [PATCH v2] ui/console: add escape sequence \e[5, 6n

Thank you for review.
OK I'll change these and send version3 later.

Ren

2016-03-08 18:40 GMT+09:00 Gerd Hoffmann <[email protected]>:

Quoted 28 lines
Quoted 6 lines
ui/console.c +5 -0
+static void console_respond_str(QemuConsole *s, const char *buf)
+{
+    TextCell *c;
+    int y1;
+    while (*buf) {
 

ui/console.c static void console_clear_xy(QemuConsole *s, int x, int y) · line 774

Quoted 10 lines
ui/console.c +10 -0
+        if (s->x >= s->width) {
+            s->x = 0;
+            console_put_lf(s);
+        }
+        y1 = (s->y_base + s->y) % s->total_height;
+        c = &s->cells[y1 * s->width + s->x];
+        c->ch = *buf;
+        c->t_attrib = s->t_attrib;
+        update_xy(s, s->x, s->y);
+        s->x++;

I think you should just call console_putchar() here instead of cut +pasting that code block.

If that doesn't work for some reason move the code block to a new function which can be called from both console_putchar() and console_respond_str().

thanks,
Gerd