summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/system/vi/vi.c37
-rw-r--r--nuttx/include/nuttx/vt100.h12
2 files changed, 35 insertions, 14 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 */
diff --git a/nuttx/include/nuttx/vt100.h b/nuttx/include/nuttx/vt100.h
index 32344a1de..4ee3a73b3 100644
--- a/nuttx/include/nuttx/vt100.h
+++ b/nuttx/include/nuttx/vt100.h
@@ -182,6 +182,17 @@
#define VT52_IDENT {ASCII_ESC, 'Z'} /* Identify what the terminal is */
#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */
+/* Format strings for VT100 sequences that require numeric arguments */
+
+#define VT100_FMT_SETWIN "\033[%d;%dr" /* Set top and bottom line#s of a window */
+#define VT100_FMT_CURSORUP "\033[%dA" /* Move cursor up n lines */
+#define VT100_FMT_CURSORDN "\033[%dB" /* Move cursor down n lines */
+#define VT100_FMT_CURSORRT "\033[%dC" /* Move cursor right n lines */
+#define VT100_FMT_CURSORLF "\033[%dD" /* Move cursor left n lines */
+#define VT100_FMT_CURSORPOS "\033[%d;%dH" /* Move cursor to screen location v,h */
+#define VT100_FMT_HVPOS "\033[%d;%df" /* Move cursor to screen location v,h */
+#define VT52_FMT_CURSORPOS "\033%d%d" /* Move cursor to v,h location */
+
/* VT100 Special Key Codes
*
* These are sent from the terminal back to the computer when the particular
@@ -196,7 +207,6 @@
#define VT100_PF3 {ASCII_ESC, 'O', 'R'}
#define VT100_PF4 {ASCII_ESC, 'O', 'S'}
-
/* Arrow keys */
#define VT100_UP_RESET {ASCII_ESC, 'A'}