diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-01-20 16:58:14 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-01-20 16:58:14 -0600 |
commit | d4b2e069a720c86b08a38599af92f8f2152fef3d (patch) | |
tree | 3c9b831ca1b34b00ba510ad0e10c8f4b02de2258 /apps/system/vi | |
parent | b06275fc5ec507e3c446622c363e6aa91de50b50 (diff) | |
download | px4-nuttx-d4b2e069a720c86b08a38599af92f8f2152fef3d.tar.gz px4-nuttx-d4b2e069a720c86b08a38599af92f8f2152fef3d.tar.bz2 px4-nuttx-d4b2e069a720c86b08a38599af92f8f2152fef3d.zip |
Fix formatting of the VT100 escapte sequence
Diffstat (limited to 'apps/system/vi')
-rw-r--r-- | apps/system/vi/vi.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/apps/system/vi/vi.c b/apps/system/vi/vi.c index 4422563ed..584ffabba 100644 --- a/apps/system/vi/vi.c +++ b/apps/system/vi/vi.c @@ -345,7 +345,8 @@ static const char g_revindex[] = VT100_REVINDEX; static const char g_attriboff[] = VT100_MODESOFF; static const char g_boldon[] = VT100_BOLD; static const char g_reverseon[] = VT100_REVERSE; -static const char g_blinkon [] = VT100_BLINK; +static const char g_blinkon[] = VT100_BLINK; +static const char g_fmtcursorpos[] = VT100_FMT_CURSORPOS; /* Error format strings */ @@ -378,7 +379,7 @@ static void vi_write(FAR struct vi_s *vi, FAR const char *buffer, ssize_t nwritten; size_t nremaining = buflen; - vivdbg("buffer=%p buflen=%d\n", buffer, (int)buflen); + //vivdbg("buffer=%p buflen=%d\n", buffer, (int)buflen); /* Loop until all bytes have been successuflly written (or until a * un-recoverable error is encountered) @@ -565,18 +566,18 @@ static void vi_cursorhome(FAR struct vi_s *vi) static void vi_setcursor(FAR struct vi_s *vi, uint16_t row, uint16_t column) { - char buffer[6]; + char buffer[16]; + int len; - /* Send the VT100 CURSORPOS command */ + vivdbg("row=%d column=%d\n", row, column); + + /* Format the cursor position command */ + + len = snprintf(buffer, 16, g_fmtcursorpos, row, column); - buffer[0] = ASCII_ESC; - buffer[1] = '['; - buffer[2] = row; - buffer[3] = ';'; - buffer[4] = column; - buffer[5] = 'H'; + /* Send the VT100 CURSORPOS command */ - vi_write(vi, buffer, 6); + vi_write(vi, buffer, len); } /**************************************************************************** @@ -1466,7 +1467,9 @@ static void vi_show(FAR struct vi_s *vi) pos < vi->textsize && row < endrow; row++) { - /* Get the last column on this row */ + /* Get the last column on this row. Avoid writing into the last byte + * on the screen which may trigger a scroll. + */ endcol = vi->display.column; if (row >= vi->display.row - 1) @@ -1505,13 +1508,21 @@ static void vi_show(FAR struct vi_s *vi) else if (vi->text[pos] == '\t') { tabcol = NEXT_TAB(column); - if (tabcol < vi->display.column - 1) + if (tabcol < endcol) { for (; column < tabcol; column++) { vi_putch(vi, ' '); } } + else + { + /* Break out of the loop... there is nothing left on the + * line but whitespace. + */ + + break; + } } /* Add the normal character to the display */ |