aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/lib/sys/ansi.c63
-rw-r--r--com32/lib/sys/ansi.h28
2 files changed, 51 insertions, 40 deletions
diff --git a/com32/lib/sys/ansi.c b/com32/lib/sys/ansi.c
index 43b3b654..17ace1d4 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 1e034246..ed4b01cb 100644
--- a/com32/lib/sys/ansi.h
+++ b/com32/lib/sys/ansi.h
@@ -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 {