]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: video: correctly set the cursor position
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Sat, 10 Nov 2018 18:55:48 +0000 (19:55 +0100)
committerAnatolij Gustschin <agust@denx.de>
Sat, 17 Nov 2018 10:35:39 +0000 (11:35 +0100)
The terminal escape sequence ESC [ <x> ; <y> H is used to set the cursor
position. According to the ECMA 48 standard the upper left corner in the
escape sequences is [1, 1]. The video uclass uses [0, 0] as upper left
corner.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/video/vidconsole-uclass.c
test/dm/video.c

index 1874887f2f3a63a9d257e95ccfac3277c3d73917..db40a1396b2f65b00535895db6db8215123ca059 100644 (file)
@@ -272,6 +272,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
                s++;    /* ; */
                s = parsenum(s, &col);
 
+               /*
+                * Video origin is [0, 0], terminal origin is [1, 1].
+                */
+               if (row)
+                       --row;
+               if (col)
+                       --col;
+
                set_cursor_position(priv, row, col);
 
                break;
index 7def338058e1f737ab862c3388fa62010b4676ee..5d1faac19c9faac56d536781473194d7653ee533 100644 (file)
@@ -178,12 +178,12 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
 
        /* test set-cursor: [%d;%df */
        vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
-       ut_asserteq(142, compress_frame_buffer(dev));
+       ut_asserteq(143, compress_frame_buffer(dev));
 
        /* test colors (30-37 fg color, 40-47 bg color) */
        vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
        vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
-       ut_asserteq(265, compress_frame_buffer(dev));
+       ut_asserteq(272, compress_frame_buffer(dev));
 
        return 0;
 }