qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/1] ui/console: add escape sequence \e[5, 6n
@ 2016-03-08 19:51 Ren Kimura
  2016-03-08 19:51 ` [Qemu-devel] [PATCH v3 1/1] " Ren Kimura
  2016-03-09  9:01 ` [Qemu-devel] [PATCH v3 0/1] " Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Ren Kimura @ 2016-03-08 19:51 UTC (permalink / raw)
  To: kraxel; +Cc: qemu-devel


I've moved code block to a new function console_put_one.
If console_putchar will be called directly from console_respond_str, it cause some problems. 
For example "\e[0n" should be printed entirely, but on the other hand, almost same escape sequence(i.e. in same switch statement)  "\e[5n" should not be printed. It's consfusing and not good.
So this way is better I think

Thanks,
 Ren

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH v3 1/1] ui/console: add escape sequence \e[5, 6n
  2016-03-08 19:51 [Qemu-devel] [PATCH v3 0/1] ui/console: add escape sequence \e[5, 6n Ren Kimura
@ 2016-03-08 19:51 ` Ren Kimura
  2016-03-09  9:01 ` [Qemu-devel] [PATCH v3 0/1] " Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Ren Kimura @ 2016-03-08 19:51 UTC (permalink / raw)
  To: kraxel; +Cc: qemu-devel

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.

Signed-off-by: Ren Kimura <rkx1209dev@gmail.com>
---
 ui/console.c | 56 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 41 insertions(+), 15 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index ae61382..8027ba7 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -757,6 +757,31 @@ static void console_clear_xy(QemuConsole *s, int x, int y)
     update_xy(s, x, y);
 }
 
+static void console_put_one(QemuConsole *s, int ch)
+{
+    TextCell *c;
+    int y1;
+    if (s->x >= s->width) {
+        /* line wrap */
+        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 = ch;
+    c->t_attrib = s->t_attrib;
+    update_xy(s, s->x, s->y);
+    s->x++;
+}
+
+static void console_respond_str(QemuConsole *s, const char *buf)
+{
+    while (*buf) {
+        console_put_one(s, *buf);
+        buf++;
+    }
+}
+
 /* set cursor, checking bounds */
 static void set_cursor(QemuConsole *s, int x, int y)
 {
@@ -779,9 +804,9 @@ static void set_cursor(QemuConsole *s, int x, int y)
 
 static void console_putchar(QemuConsole *s, int ch)
 {
-    TextCell *c;
-    int y1, i;
+    int i;
     int x, y;
+    char response[40];
 
     switch(s->state) {
     case TTY_STATE_NORM:
@@ -817,17 +842,7 @@ static void console_putchar(QemuConsole *s, int ch)
             s->state = TTY_STATE_ESC;
             break;
         default:
-            if (s->x >= s->width) {
-                /* line wrap */
-                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 = ch;
-            c->t_attrib = s->t_attrib;
-            update_xy(s, s->x, s->y);
-            s->x++;
+            console_put_one(s, ch);
             break;
         }
         break;
@@ -956,8 +971,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 */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/1] ui/console: add escape sequence \e[5, 6n
  2016-03-08 19:51 [Qemu-devel] [PATCH v3 0/1] ui/console: add escape sequence \e[5, 6n Ren Kimura
  2016-03-08 19:51 ` [Qemu-devel] [PATCH v3 1/1] " Ren Kimura
@ 2016-03-09  9:01 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2016-03-09  9:01 UTC (permalink / raw)
  To: Ren Kimura; +Cc: qemu-devel

On Mi, 2016-03-09 at 04:51 +0900, Ren Kimura wrote:
> I've moved code block to a new function console_put_one.

Good, patch added to the queue.

thanks,
  Gerd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-09  9:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-08 19:51 [Qemu-devel] [PATCH v3 0/1] ui/console: add escape sequence \e[5, 6n Ren Kimura
2016-03-08 19:51 ` [Qemu-devel] [PATCH v3 1/1] " Ren Kimura
2016-03-09  9:01 ` [Qemu-devel] [PATCH v3 0/1] " Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).