From aa31b1297e4aabeb1c939afff5f262ede39f80ef Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 15 Jul 2012 11:55:51 +0200 Subject: [PATCH] vte: implement device status reports (DSR) DSRs are used to query the terminal for data. This includes general status reports but also cursor positions. We currently only implement VT220 features. DEC later introduced further modes to query more advanced interfaces. Signed-off-by: David Herrmann --- src/vte.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/vte.c b/src/vte.c index 8b668ec..d7dcf5d 100644 --- a/src/vte.c +++ b/src/vte.c @@ -49,6 +49,7 @@ */ #include +#include #include #include #include @@ -1233,6 +1234,24 @@ static void csi_dev_attr(struct kmscon_vte *vte) vte->csi_argv[0], vte->csi_argv[1], vte->csi_argv[2]); } +static void csi_dsr(struct kmscon_vte *vte) +{ + char buf[64]; + unsigned int x, y, len; + + if (vte->csi_argv[0] == 5) { + vte_write(vte, "\e[0n", 4); + } else if (vte->csi_argv[0] == 6) { + x = kmscon_console_get_cursor_x(vte->con); + y = kmscon_console_get_cursor_y(vte->con); + len = snprintf(buf, sizeof(buf), "\e[%u;%uR", x, y); + if (len >= sizeof(buf)) + vte_write(vte, "\e[0;0R", 6); + else + vte_write(vte, buf, len); + } +} + static void do_csi(struct kmscon_vte *vte, uint32_t data) { int num, x, y, upper, lower; @@ -1415,6 +1434,10 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = 1; kmscon_console_tab_right(vte->con, num); break; + case 'n': /* DSR */ + /* device status reports */ + csi_dsr(vte); + break; default: log_debug("unhandled CSI sequence %c", data); }