]> git.lizzy.rs Git - linenoise.git/commitdiff
Fix linenoise serial console window size for vt102
authorSteve Bennett <steveb@workware.net.au>
Wed, 31 Oct 2012 03:17:24 +0000 (13:17 +1000)
committerSteve Bennett <steveb@workware.net.au>
Wed, 31 Oct 2012 09:56:55 +0000 (19:56 +1000)
This includes minicom, which doesn't support hpa (CHA), only cuf.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
linenoise.c

index 5c1672a08c9523cf80345ed39c82b60c0eb48700..5d82865daafc14819a1d2ddee9c0972ccd7f73d1 100644 (file)
  * flickering effect with some slow terminal, but the lesser sequences
  * the more compatible.
  *
- * CHA (Cursor Horizontal Absolute)
- *    Sequence: ESC [ n G
- *    Effect: moves cursor to column n (1 based)
- *
  * EL (Erase Line)
  *    Sequence: ESC [ n K
  *    Effect: if n is 0 or missing, clear from cursor to end of line
  *    Sequence: ESC [ n C
  *    Effect: moves cursor forward of n chars
  *
+ * CR (Carriage Return)
+ *    Sequence: \r
+ *    Effect: moves cursor to column 1
+ *
  * The following are used to clear the screen: ESC [ H ESC [ 2 J
  * This is actually composed of two sequences:
  *
@@ -293,7 +293,7 @@ static void clearScreen(struct current *current)
 
 static void cursorToLeft(struct current *current)
 {
-    fd_printf(current->fd, "\x1b[1G");
+    fd_printf(current->fd, "\r");
 }
 
 static int outputChars(struct current *current, const char *buf, int len)
@@ -303,7 +303,7 @@ static int outputChars(struct current *current, const char *buf, int len)
 
 static void outputControlChar(struct current *current, char ch)
 {
-    fd_printf(current->fd, "\033[7m^%c\033[0m", ch);
+    fd_printf(current->fd, "\x1b[7m^%c\x1b[0m", ch);
 }
 
 static void eraseEol(struct current *current)
@@ -313,7 +313,7 @@ static void eraseEol(struct current *current)
 
 static void setCursorPos(struct current *current, int x)
 {
-    fd_printf(current->fd, "\x1b[1G\x1b[%dC", x);
+    fd_printf(current->fd, "\r\x1b[%dC", x);
 }
 
 /**
@@ -392,8 +392,8 @@ static int getWindowSize(struct current *current)
     if (current->cols == 0) {
         current->cols = 80;
 
-        /* Move cursor far right and report cursor position */
-        fd_printf(current->fd, "\x1b[999G" "\x1b[6n");
+        /* Move cursor far right and report cursor position, then back to the left */
+        fd_printf(current->fd, "\x1b[999C" "\x1b[6n");
 
         /* Parse the response: ESC [ rows ; cols R */
         if (fd_read_char(current->fd, 100) == 0x1b && fd_read_char(current->fd, 100) == '[') {