From: H. Peter Anvin Date: Fri, 14 Aug 2009 05:35:28 +0000 (-0700) Subject: ansi: add support for no-wrap mode, cleanups X-Git-Tag: syslinux-3.84-pre1~37^2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86e26798966e1a47673b07692d383da0ead63873;p=platform%2Fupstream%2Fsyslinux.git ansi: add support for no-wrap mode, cleanups 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 --- diff --git a/com32/lib/sys/ansi.c b/com32/lib/sys/ansi.c index 43b3b65..17ace1d 100644 --- a/com32/lib/sys/ansi.c +++ b/com32/lib/sys/ansi.c @@ -36,21 +36,22 @@ #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--; diff --git a/com32/lib/sys/ansi.h b/com32/lib/sys/ansi.h index 1e03424..ed4b01c 100644 --- a/com32/lib/sys/ansi.h +++ b/com32/lib/sys/ansi.h @@ -6,6 +6,7 @@ #define COM32_LIB_SYS_ANSI_H #include +#include #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 {