{"id":811159,"url":"http://patchwork.ozlabs.org/api/patches/811159/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20170907202816.18765-1-robdclark@gmail.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170907202816.18765-1-robdclark@gmail.com>","list_archive_url":null,"date":"2017-09-07T20:28:09","name":"[U-Boot] dm: video: Add basic ANSI escape sequence support","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"015237af4662a5f5b37ab3226f80f17e80c12691","submitter":{"id":18760,"url":"http://patchwork.ozlabs.org/api/people/18760/?format=json","name":"Rob Clark","email":"robdclark@gmail.com"},"delegate":{"id":1700,"url":"http://patchwork.ozlabs.org/api/users/1700/?format=json","username":"ag","first_name":"Anatolij","last_name":"Gustschin","email":"agust@denx.de"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20170907202816.18765-1-robdclark@gmail.com/mbox/","series":[{"id":2056,"url":"http://patchwork.ozlabs.org/api/series/2056/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=2056","date":"2017-09-07T20:28:09","name":"[U-Boot] dm: video: Add basic ANSI escape sequence support","version":1,"mbox":"http://patchwork.ozlabs.org/series/2056/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811159/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811159/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"DrkCdh9k\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xpBqM54Xyz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 06:28:31 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 634DDC21EA2; Thu,  7 Sep 2017 20:28:26 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 1E876C21D70;\n\tThu,  7 Sep 2017 20:28:23 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 46534C21D70; Thu,  7 Sep 2017 20:28:22 +0000 (UTC)","from mail-qk0-f194.google.com (mail-qk0-f194.google.com\n\t[209.85.220.194])\n\tby lists.denx.de (Postfix) with ESMTPS id B486CC21C72\n\tfor <u-boot@lists.denx.de>; Thu,  7 Sep 2017 20:28:21 +0000 (UTC)","by mail-qk0-f194.google.com with SMTP id r66so296543qke.4\n\tfor <u-boot@lists.denx.de>; Thu, 07 Sep 2017 13:28:21 -0700 (PDT)","from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id\n\tf20sm122512qta.86.2017.09.07.13.28.18\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 07 Sep 2017 13:28:18 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id;\n\tbh=SMhe45Z7n1m/7TQ3jLNAq/LRyyKTKxbbcNCGlvBrCnE=;\n\tb=DrkCdh9kUdfTjK5WusuItffNx5Ik9h+PeJdRNMsNc4DALsDbZ4E6tpdLQHLeouEVId\n\tieYbUAo112mXp6NCte9PwOwVwBvYJdUdgSEBPV3fWg5nOfIXNK15u98DBKYBNvs0gDqH\n\t1XIHc0E8R/eynZNaZxZUkefBAtlPucsEZe6UAj+zT7NkjHkDQEpqxfaBrH3HE4Ao26zJ\n\tMQ6IyGJJiRPRl/X7wXuloYDwpJ89DuI82f8BvBd6t3rLT+niv3xVzDYL4jW1TAMdSj0c\n\t6eoIuyW/VYCrJjOo35Sx1oYLESjT1N0OHS/6Ktoy8jS2Yk4dw2JzyEMjCxoVYSmpMuC9\n\tFv5Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id;\n\tbh=SMhe45Z7n1m/7TQ3jLNAq/LRyyKTKxbbcNCGlvBrCnE=;\n\tb=pkDb6giERAzfPKjOQVw6aEo25yxN/tRWPOH9gpgj1herlj9J6NoF8oI+kjekUtdZ/l\n\tTmLGFUJZwnhocw5ZUya4iHbRnL8gYFN58v0Y+v/bSzakeBhdKRY9QOE+j9M4ezlRYyv4\n\t8Q2sojW4zWJWX6ESloxfwmfJg6tVFUKcXBcJFERPZCXI18xHnVKyk/0m8s6drAtCREkz\n\t/5KoBeUGOQ+BGcTDnmtncohl8AcOLSkQPRsmk9tHfAGvHnYWM3vg42vdm1iQ9bydlYcc\n\tSFX16SL2Z7U+LVorqL8yawXLr2kqr02cGZ/kfNYXtXyDKU5kKHcL4UpqVx7rTqQQYcIf\n\t0zGA==","X-Gm-Message-State":"AHPjjUjCKWu8OlVfz0Kv10XKXhApn1TFmTO3DEVOBGlXD4rrVBzEQup+\n\totB9V5Zml15NIxzjSJs=","X-Google-Smtp-Source":"AOwi7QAzH9ypfMaX2Nz+vMknjv/aRYPhGde4Dpf5L2wiXoZ0rLlfvhYxHlCa9zd7a0SOIcKrVJG+uw==","X-Received":"by 10.233.230.66 with SMTP id x2mr784572qkl.340.1504816100037;\n\tThu, 07 Sep 2017 13:28:20 -0700 (PDT)","From":"Rob Clark <robdclark@gmail.com>","To":"U-Boot Mailing List <u-boot@lists.denx.de>","Date":"Thu,  7 Sep 2017 16:28:09 -0400","Message-Id":"<20170907202816.18765-1-robdclark@gmail.com>","X-Mailer":"git-send-email 2.13.5","Subject":"[U-Boot] [PATCH] dm: video: Add basic ANSI escape sequence support","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"},"content":"Really just the subset that is needed by efi_console.  Perhaps more will\nbe added later, for example color support would be useful to implement\nefi_cout_set_attribute().\n\nSigned-off-by: Rob Clark <robdclark@gmail.com>\n---\n drivers/video/vidconsole-uclass.c | 112 ++++++++++++++++++++++++++++++++++++++\n drivers/video/video-uclass.c      |   4 +-\n include/video.h                   |   7 +++\n include/video_console.h           |  11 ++++\n 4 files changed, 131 insertions(+), 3 deletions(-)","diff":"diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c\nindex e081d5a0ee..7998b4cf5f 100644\n--- a/drivers/video/vidconsole-uclass.c\n+++ b/drivers/video/vidconsole-uclass.c\n@@ -9,6 +9,7 @@\n  */\n \n #include <common.h>\n+#include <linux/ctype.h>\n #include <dm.h>\n #include <video.h>\n #include <video_console.h>\n@@ -107,12 +108,123 @@ static void vidconsole_newline(struct udevice *dev)\n \tvideo_sync(dev->parent);\n }\n \n+/*\n+ * Parse a number from string that ends in a non-numeric character..\n+ * sscanf() would be nice.  This is just enough for parsing ANSI escape\n+ * sequences.\n+ */\n+static char *parsenum(char *s, int *num)\n+{\n+\tint n = 0;\n+\n+\twhile (isdigit(*s)) {\n+\t\tn = (10 * n) + (*s - '0');\n+\t\ts++;\n+\t}\n+\n+\t*num = n;\n+\treturn s;\n+}\n+\n+static void vidconsole_escape_char(struct udevice *dev, char ch)\n+{\n+\tstruct vidconsole_priv *priv = dev_get_uclass_priv(dev);\n+\n+\t/* Sanity checking for bogus ESC sequences: */\n+\tif (priv->escape_len >= sizeof(priv->escape_buf))\n+\t\tgoto error;\n+\tif (priv->escape_len == 0 && ch != '[')\n+\t\tgoto error;\n+\n+\tpriv->escape_buf[priv->escape_len++] = ch;\n+\n+\t/*\n+\t * Escape sequences are terminated by a letter, so keep\n+\t * accumulating until we get one:\n+\t */\n+\tif (!isalpha(ch))\n+\t\treturn;\n+\n+\t/*\n+\t * clear escape mode first, otherwise things will get highly\n+\t * surprising if you hit any debug prints that come back to\n+\t * this console.\n+\t */\n+\tpriv->escape = 0;\n+\n+\tswitch (ch) {\n+\tcase 'H':\n+\tcase 'f': {\n+\t\tint row, col;\n+\t\tchar *s = priv->escape_buf;\n+\n+\t\t/*\n+\t\t * Set cursor position: [%d;%df or [%d;%dH\n+\t\t */\n+\t\ts++;    /* [ */\n+\t\ts = parsenum(s, &row);\n+\t\ts++;    /* ; */\n+\t\ts = parsenum(s, &col);\n+\n+\t\tpriv->ycur = row * priv->y_charsize;\n+\t\tpriv->xcur_frac = priv->xstart_frac +\n+\t\t\tVID_TO_POS(col * priv->x_charsize);\n+\n+\t\tbreak;\n+\t}\n+\tcase 'J': {\n+\t\tint mode;\n+\n+\t\t/*\n+\t\t * Clear part/all screen:\n+\t\t *   [J or [0J - clear screen from cursor down\n+\t\t *   [1J       - clear screen from cursor up\n+\t\t *   [2J       - clear entire screen\n+\t\t *\n+\t\t * TODO we really only handle entire-screen case, others\n+\t\t * probably require some additions to video-uclass (and\n+\t\t * are not really needed yet by efi_console)\n+\t\t */\n+\t\tparsenum(priv->escape_buf + 1, &mode);\n+\n+\t\tif (mode == 2) {\n+\t\t\tvideo_clear(dev->parent);\n+\t\t\tvideo_sync(dev->parent);\n+\t\t\tpriv->ycur = 0;\n+\t\t\tpriv->xcur_frac = priv->xstart_frac;\n+\t\t} else {\n+\t\t\tdebug(\"unsupported clear mode: %d\\n\", mode);\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tdebug(\"unrecognized escape sequence: %*s\\n\",\n+\t\t      priv->escape_len, priv->escape_buf);\n+\t}\n+\n+\treturn;\n+\n+error:\n+\t/* something went wrong, just revert to normal mode: */\n+\tpriv->escape = 0;\n+\treturn;\n+}\n+\n int vidconsole_put_char(struct udevice *dev, char ch)\n {\n \tstruct vidconsole_priv *priv = dev_get_uclass_priv(dev);\n \tint ret;\n \n+\tif (priv->escape) {\n+\t\tvidconsole_escape_char(dev, ch);\n+\t\treturn 0;\n+\t}\n+\n \tswitch (ch) {\n+\tcase '\\x1b':\n+\t\tpriv->escape_len = 0;\n+\t\tpriv->escape = 1;\n+\t\tbreak;\n \tcase '\\a':\n \t\t/* beep */\n \t\tbreak;\ndiff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c\nindex dfa39b0d1b..dcaceed42c 100644\n--- a/drivers/video/video-uclass.c\n+++ b/drivers/video/video-uclass.c\n@@ -87,7 +87,7 @@ int video_reserve(ulong *addrp)\n \treturn 0;\n }\n \n-static int video_clear(struct udevice *dev)\n+void video_clear(struct udevice *dev)\n {\n \tstruct video_priv *priv = dev_get_uclass_priv(dev);\n \n@@ -100,8 +100,6 @@ static int video_clear(struct udevice *dev)\n \t} else {\n \t\tmemset(priv->fb, priv->colour_bg, priv->fb_size);\n \t}\n-\n-\treturn 0;\n }\n \n /* Flush video activity to the caches */\ndiff --git a/include/video.h b/include/video.h\nindex 5b4e78b182..61ff653121 100644\n--- a/include/video.h\n+++ b/include/video.h\n@@ -115,6 +115,13 @@ struct video_ops {\n int video_reserve(ulong *addrp);\n \n /**\n+ * video_clear() - Clear a device's frame buffer to background color.\n+ *\n+ * @dev:\tDevice to clear\n+ */\n+void video_clear(struct udevice *dev);\n+\n+/**\n  * video_sync() - Sync a device's frame buffer with its hardware\n  *\n  * Some frame buffers are cached or have a secondary frame buffer. This\ndiff --git a/include/video_console.h b/include/video_console.h\nindex 26047934da..9dce234bd9 100644\n--- a/include/video_console.h\n+++ b/include/video_console.h\n@@ -29,6 +29,9 @@\n  * @xsize_frac:\tWidth of the display in fractional units\n  * @xstart_frac:\tLeft margin for the text console in fractional units\n  * @last_ch:\tLast character written to the text console on this line\n+ * @escape:\tTRUE if currently accumulating an ANSI escape sequence\n+ * @escape_len:\tLength of accumulated escape sequence so far\n+ * @escape_buf:\tBuffer to accumulate escape sequence\n  */\n struct vidconsole_priv {\n \tstruct stdio_dev sdev;\n@@ -42,6 +45,14 @@ struct vidconsole_priv {\n \tint xsize_frac;\n \tint xstart_frac;\n \tint last_ch;\n+\t/*\n+\t * ANSI escape sequences are accumulated character by character,\n+\t * starting after the ESC char (0x1b) until the entire sequence\n+\t * is consumed at which point it is acted upon.\n+\t */\n+\tint escape;\n+\tint escape_len;\n+\tchar escape_buf[32];\n };\n \n /**\n","prefixes":["U-Boot"]}