ansi: add support for no-wrap mode, cleanups
authorH. Peter Anvin <hpa@zytor.com>
Fri, 14 Aug 2009 05:35:28 +0000 (22:35 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Sat, 5 Sep 2009 04:10:23 +0000 (21:10 -0700)
Add support for nowrap mode CSI ? 7 l (unfortunately, on ANSI.SYS it
is CSI = 7 l; which means that the only way to support both is to
print both sequences and then erase the resulting garbage.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/lib/sys/ansi.c
com32/lib/sys/ansi.h

index 43b3b65..17ace1d 100644 (file)
 #include "ansi.h"
 
 static const struct term_state default_state = {
+    .state = st_init,
+    .pvt = false,
+    .nparms = 0,
     .xy = {0, 0},
     .cindex = 0,               /* First color table entry */
-    .vtgraphics = 0,
+    .vtgraphics = false,
     .intensity = 1,
-    .underline = 0,
-    .blink = 0,
-    .reverse = 0,
+    .underline = false,
+    .blink = false,
+    .reverse = false,
     .fg = 7,
     .bg = 0,
-    .autocr = 1,               /* Mimic \n -> \r\n conversion by default */
+    .autocr = true,            /* Mimic \n -> \r\n conversion by default */
+    .autowrap = true,          /* Wrap lines by default */
     .saved_xy = {0, 0},
-    .cursor = 1,
-    .state = st_init,
-    .pvt = 0,
-    .nparms = 0,
+    .cursor = true,
 };
 
 /* DEC VT graphics to codepage 437 table (characters 0x60-0x7F only) */
@@ -141,7 +142,8 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
            break;
        case '[':
            st->state = st_csi;
-           st->nparms = st->pvt = 0;
+           st->nparms = 0;
+           st->pvt = false;
            memset(st->parms, 0, sizeof st->parms);
            break;
        case 'c':
@@ -170,7 +172,7 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
                    st->nparms = ANSI_MAX_PARMS - 1;
                break;
            } else if (ch == '?') {
-               st->pvt = 1;
+               st->pvt = true;
            } else {
                switch (ch) {
                case 'A':
@@ -278,22 +280,25 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
                    break;
                case 'h':
                case 'l':
-                   {
-                       int set = (ch == 'h');
-                       switch (st->parms[0]) {
-                       case 20:
-                           st->autocr = set;
-                           break;
-                       case 25:
-                           st->cursor = set;
-                           op->showcursor(st);
-                           break;
-                       default:
-                           /* Ignore */
-                           break;
-                       }
+               {
+                   bool set = (ch == 'h');
+                   switch (st->parms[0]) {
+                   case 7:     /* DECAWM */
+                       st->autowrap = set;
+                       break;
+                   case 20:    /* LNM */
+                       st->autocr = set;
+                       break;
+                   case 25:    /* DECTECM */
+                       st->cursor = set;
+                       op->showcursor(st);
+                       break;
+                   default:
+                       /* Ignore */
+                       break;
                    }
                    break;
+               }
                case 'm':
                    {
                        static const int ansi2pc[8] =
@@ -421,8 +426,12 @@ void __ansi_putchar(const struct term_info *ti, uint8_t ch)
 
     /* If we fell off the end of the screen, adjust */
     if (xy.x >= cols) {
-       xy.x = 0;
-       xy.y++;
+       if (st->autowrap) {
+           xy.x = 0;
+           xy.y++;
+       } else {
+           xy.x = cols - 1;
+       }
     }
     while (xy.y >= rows) {
        xy.y--;
index 1e03424..ed4b01c 100644 (file)
@@ -6,6 +6,7 @@
 #define COM32_LIB_SYS_ANSI_H
 
 #include <inttypes.h>
+#include <stdbool.h>
 
 #define ANSI_MAX_PARMS 16
 
@@ -27,22 +28,23 @@ struct curxy {
 } __attribute__ ((packed));
 
 struct term_state {
-    struct curxy xy;
-    int cindex;                        /* SOH color index */
-    int vtgraphics;            /* VT graphics on/off */
-    int intensity;
-    int underline;
-    int blink;
-    int reverse;
-    int fg;
-    int bg;
-    int autocr;
-    struct curxy saved_xy;
-    int cursor;
     enum ansi_state state;
-    int pvt;                   /* Private code? */
     int nparms;                        /* Number of parameters seen */
     int parms[ANSI_MAX_PARMS];
+    bool pvt;                  /* Private code? */
+    struct curxy xy;
+    struct curxy saved_xy;
+    uint8_t cindex;            /* SOH color index */
+    uint8_t fg;
+    uint8_t bg;
+    uint8_t intensity;
+    bool vtgraphics;           /* VT graphics on/off */
+    bool underline;
+    bool blink;
+    bool reverse;
+    bool autocr;
+    bool autowrap;
+    bool cursor;
 };
 
 struct ansi_ops {