#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) */
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':
st->nparms = ANSI_MAX_PARMS - 1;
break;
} else if (ch == '?') {
- st->pvt = 1;
+ st->pvt = true;
} else {
switch (ch) {
case 'A':
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] =
/* 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--;
#define COM32_LIB_SYS_ANSI_H
#include <inttypes.h>
+#include <stdbool.h>
#define ANSI_MAX_PARMS 16
} __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 {