aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/term/term.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 13:15:14 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 13:15:14 -0700
commitc320322dffd8f4648cc24ab731ac64dda6eec77d (patch)
tree9c668d1e1a331991abeb8aa3b838ba470be7252b /sys/cmd/term/term.c
parent7b5b105d84103d4320de510f0fdab345b5d2f477 (diff)
changed all caps
Diffstat (limited to 'sys/cmd/term/term.c')
-rw-r--r--sys/cmd/term/term.c535
1 files changed, 267 insertions, 268 deletions
diff --git a/sys/cmd/term/term.c b/sys/cmd/term/term.c
index 38fd725..81dd937 100644
--- a/sys/cmd/term/term.c
+++ b/sys/cmd/term/term.c
@@ -1,11 +1,10 @@
/* See LICENSE for license details. */
+#include "term.h"
+
#include <pwd.h>
#include <termios.h>
#include <wchar.h>
-#include "term.h"
-#include "win.h"
-
#if defined(__linux)
#include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
@@ -14,7 +13,7 @@
#include <libutil.h>
#endif
-/* Arbitrary sizes */
+/* arbitrary sizes */
#define ESC_BUF_SIZ (128*UTFmax)
#define ESC_ARG_SIZ 16
#define STR_BUF_SIZ ESC_BUF_SIZ
@@ -27,51 +26,56 @@
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
-enum term_mode {
- MODE_WRAP = 1 << 0,
- MODE_INSERT = 1 << 1,
- MODE_ALTSCREEN = 1 << 2,
- MODE_CRLF = 1 << 3,
- MODE_ECHO = 1 << 4,
- MODE_PRINT = 1 << 5,
- MODE_UTF8 = 1 << 6,
- MODE_SIXEL = 1 << 7,
+/* terminal mode */
+enum {
+ Twrap = iota(0),
+ Tinsert = iota(1),
+ Taltscreen = iota(2),
+ Tcrlf = iota(3),
+ Techo = iota(4),
+ Tprint = iota(5),
+ Tutf8 = iota(6),
+ Tsixel = iota(7),
};
-enum cursor_movement {
- CURSOR_SAVE,
- CURSOR_LOAD
+/* cursor state */
+enum {
+ CursorSave,
+ CursorLoad
};
-enum cursor_state {
- CURSOR_DEFAULT = 0,
- CURSOR_WRAPNEXT = 1,
- CURSOR_ORIGIN = 2
+/* cursor mode */
+enum {
+ CursorDefault = 0,
+ CursorWrap = 1,
+ CursorOrigin = 2
};
-enum charset {
- CS_GRAPHIC0,
- CS_GRAPHIC1,
- CS_UK,
- CS_USA,
- CS_MULTI,
- CS_GER,
- CS_FIN
+/* character set */
+enum {
+ CSgfx0,
+ CSgfx1,
+ CSuk,
+ CSusa,
+ CSmulti,
+ CSger,
+ CSfin,
};
-enum escape_state {
- ESC_START = 1,
- ESC_CSI = 2,
- ESC_STR = 4, /* OSC, PM, APC */
- ESC_ALTCHARSET = 8,
- ESC_STR_END = 16, /* a final string was encountered */
- ESC_TEST = 32, /* Enter in test mode */
- ESC_UTF8 = 64,
- ESC_DCS =128,
+/* escape sequences */
+enum {
+ Xstart = 1,
+ Xcsi = 2,
+ Xstr = 4, /* OSC, PM, APC */
+ Xaltcs = 8,
+ Xstrend = 16, /* a final string was encountered */
+ Xtest = 32, /* Enter in test mode */
+ Xutf8 = 64,
+ Xdcs =128,
};
typedef struct {
- Glyph attr; /* current char attributes */
+ Letter attr; /* current char attributes */
int x;
int y;
char state;
@@ -97,22 +101,22 @@ typedef struct {
/* Internal representation of the screen */
typedef struct {
- int row; /* nb row */
- int col; /* nb col */
+ int row; /* nb row */
+ int col; /* nb col */
Line *line; /* screen */
Line *alt; /* alternate screen */
- int *dirty; /* dirtyness of lines */
+ int *dirty; /* dirtyness of lines */
TCursor c; /* cursor */
- int ocx; /* old cursor col */
- int ocy; /* old cursor row */
- int top; /* top scroll limit */
- int bot; /* bottom scroll limit */
- int mode; /* terminal mode flags */
- int esc; /* escape state flags */
+ int ocx; /* old cursor col */
+ int ocy; /* old cursor row */
+ int top; /* top scroll limit */
+ int bot; /* bottom scroll limit */
+ int mode; /* terminal mode flags */
+ int esc; /* escape state flags */
char trantbl[4]; /* charset table translation */
- int charset; /* current charset */
- int icharset; /* selected charset for sequence */
- int *tabs;
+ int charset; /* current charset */
+ int icharset; /* selected charset for sequence */
+ int *tabs;
rune lastc; /* last printed char outside of sequence, 0 if control */
} Term;
@@ -143,60 +147,60 @@ static void stty(char **);
static void sigchld(int);
static void ttywriteraw(char *, size_t);
-static void csidump(void);
-static void csihandle(void);
-static void csiparse(void);
-static void csireset(void);
-static int eschandle(uchar);
-static void strdump(void);
-static void strhandle(void);
-static void strparse(void);
-static void strreset(void);
-
-static void tprinter(char *, size_t);
-static void tdumpsel(void);
-static void tdumpline(int);
-static void tdump(void);
-static void tclearregion(int, int, int, int);
-static void tcursor(int);
-static void tdeletechar(int);
-static void tdeleteline(int);
-static void tinsertblank(int);
-static void tinsertblankline(int);
-static int tlinelen(int);
-static void tmoveto(int, int);
-static void tmoveato(int, int);
-static void tnewline(int);
-static void tputtab(int);
-static void tputc(rune);
-static void treset(void);
-static void tscrollup(int, int);
-static void tscrolldown(int, int);
-static void tsetattr(int *, int);
-static void tsetchar(rune, Glyph *, int, int);
-static void tsetdirt(int, int);
-static void tsetscroll(int, int);
-static void tswapscreen(void);
-static void tsetmode(int, int, int *, int);
-static int twrite(char *, int, int);
-static void tfulldirt(void);
-static void tcontrolcode(uchar );
-static void tdectest(char );
-static void tdefutf8(char);
-static int32_t tdefcolor(int *, int *, int);
-static void tdeftran(char);
-static void tstrsequence(uchar);
-
-static void drawregion(int, int, int, int);
-
-static void selnormalize(void);
-static void selscroll(int, int);
-static void selsnap(int *, int *, int);
-
-static char *base64dec(char *);
-static char base64dec_getc(char **);
-
-static ssize_t xwrite(int, char *, size_t);
+static void csidump(void);
+static void csihandle(void);
+static void csiparse(void);
+static void csireset(void);
+static int eschandle(uchar);
+static void strdump(void);
+static void strhandle(void);
+static void strparse(void);
+static void strreset(void);
+
+static void tprinter(char *, size_t);
+static void tdumpsel(void);
+static void tdumpline(int);
+static void tdump(void);
+static void tclearregion(int, int, int, int);
+static void tcursor(int);
+static void tdeletechar(int);
+static void tdeleteline(int);
+static void tinsertblank(int);
+static void tinsertblankline(int);
+static int tlinelen(int);
+static void tmoveto(int, int);
+static void tmoveato(int, int);
+static void tnewline(int);
+static void tputtab(int);
+static void tputc(rune);
+static void treset(void);
+static void tscrollup(int, int);
+static void tscrolldown(int, int);
+static void tsetattr(int *, int);
+static void tsetchar(rune, Letter *, int, int);
+static void tsetdirt(int, int);
+static void tsetscroll(int, int);
+static void tswapscreen(void);
+static void tsetmode(int, int, int *, int);
+static int twrite(char *, int, int);
+static void tfulldirt(void);
+static void tcontrolcode(uchar );
+static void tdectest(char );
+static void tdefutf8(char);
+static int32 tdefcolor(int *, int *, int);
+static void tdeftran(char);
+static void tstrsequence(uchar);
+
+static void drawregion(int, int, int, int);
+
+static void selnormalize(void);
+static void selscroll(int, int);
+static void selsnap(int *, int *, int);
+
+static char *base64dec(char *);
+static char base64dec_getc(char **);
+
+static uintptr xwrite(int, char *, size_t);
extern int wcwidth(wchar_t wc);
@@ -209,12 +213,7 @@ static int iofd = 1;
static int cmdfd;
static pid_t pid;
-static uchar utfbyte[UTFmax + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
-static uchar utfmask[UTFmax + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
-static rune utfmin[UTFmax + 1] = { 0, 0, 0x80, 0x800, 0x10000};
-static rune utfmax[UTFmax + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
-
-ssize_t
+uintptr
xwrite(int fd, char *s, size_t len)
{
size_t aux = len;
@@ -317,7 +316,7 @@ base64dec(char *src)
void
selinit(void)
{
- sel.mode = SEL_IDLE;
+ sel.mode = SelIdle;
sel.snap = 0;
sel.ob.x = -1;
}
@@ -327,7 +326,7 @@ tlinelen(int y)
{
int i = term.col;
- if (term.line[y][i - 1].mode & ATTR_WRAP)
+ if (term.line[y][i - 1].mode & Gwrap)
return i;
while (i > 0 && term.line[y][i - 1].u == ' ')
@@ -340,16 +339,16 @@ void
selstart(int col, int row, int snap)
{
selclear();
- sel.mode = SEL_EMPTY;
- sel.type = SEL_REGULAR;
- sel.alt = IS_SET(MODE_ALTSCREEN);
+ sel.mode = SelEmpty;
+ sel.type = SelRegular;
+ sel.alt = IS_SET(Taltscreen);
sel.snap = snap;
sel.oe.x = sel.ob.x = col;
sel.oe.y = sel.ob.y = row;
selnormalize();
if (sel.snap != 0)
- sel.mode = SEL_READY;
+ sel.mode = SelReady;
tsetdirt(sel.nb.y, sel.ne.y);
}
@@ -358,9 +357,9 @@ selextend(int col, int row, int type, int done)
{
int oldey, oldex, oldsby, oldsey, oldtype;
- if (sel.mode == SEL_IDLE)
+ if (sel.mode == SelIdle)
return;
- if (done && sel.mode == SEL_EMPTY) {
+ if (done && sel.mode == SelEmpty) {
selclear();
return;
}
@@ -376,10 +375,10 @@ selextend(int col, int row, int type, int done)
selnormalize();
sel.type = type;
- if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY)
+ if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SelEmpty)
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
- sel.mode = done ? SEL_IDLE : SEL_READY;
+ sel.mode = done ? SelIdle : SelReady;
}
void
@@ -387,7 +386,7 @@ selnormalize(void)
{
int i;
- if (sel.type == SEL_REGULAR && sel.ob.y != sel.oe.y) {
+ if (sel.type == SelRegular && sel.ob.y != sel.oe.y) {
sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x;
sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x;
} else {
@@ -401,7 +400,7 @@ selnormalize(void)
selsnap(&sel.ne.x, &sel.ne.y, +1);
/* expand selection over line breaks */
- if (sel.type == SEL_RECTANGULAR)
+ if (sel.type == SelRectangular)
return;
i = tlinelen(sel.nb.y);
if (i < sel.nb.x)
@@ -413,11 +412,11 @@ selnormalize(void)
int
selected(int x, int y)
{
- if (sel.mode == SEL_EMPTY || sel.ob.x == -1 ||
- sel.alt != IS_SET(MODE_ALTSCREEN))
+ if (sel.mode == SelEmpty || sel.ob.x == -1 ||
+ sel.alt != IS_SET(Taltscreen))
return 0;
- if (sel.type == SEL_RECTANGULAR)
+ if (sel.type == SelRectangular)
return BETWEEN(y, sel.nb.y, sel.ne.y)
&& BETWEEN(x, sel.nb.x, sel.ne.x);
@@ -431,10 +430,10 @@ selsnap(int *x, int *y, int direction)
{
int newx, newy, xt, yt;
int delim, prevdelim;
- Glyph *gp, *prevgp;
+ Letter *gp, *prevgp;
switch (sel.snap) {
- case SNAP_WORD:
+ case SnapWord:
/*
* Snap around if the word wraps around at the end or
* beginning of a line.
@@ -454,7 +453,7 @@ selsnap(int *x, int *y, int direction)
yt = *y, xt = *x;
else
yt = newy, xt = newx;
- if (!(term.line[yt][xt].mode & ATTR_WRAP))
+ if (!(term.line[yt][xt].mode & Gwrap))
break;
}
@@ -463,7 +462,7 @@ selsnap(int *x, int *y, int direction)
gp = &term.line[newy][newx];
delim = ISDELIM(gp->u);
- if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
+ if (!(gp->mode & Gwdummy) && (delim != prevdelim
|| (delim && gp->u != prevgp->u)))
break;
@@ -473,7 +472,7 @@ selsnap(int *x, int *y, int direction)
prevdelim = delim;
}
break;
- case SNAP_LINE:
+ case SnapLine:
/*
* Snap around if the the previous line or the current one
* has set ATTR_WRAP at its end. Then the whole next or
@@ -483,14 +482,14 @@ selsnap(int *x, int *y, int direction)
if (direction < 0) {
for (; *y > 0; *y += direction) {
if (!(term.line[*y-1][term.col-1].mode
- & ATTR_WRAP)) {
+ & Gwrap)) {
break;
}
}
} else if (direction > 0) {
for (; *y < term.row-1; *y += direction) {
if (!(term.line[*y][term.col-1].mode
- & ATTR_WRAP)) {
+ & Gwrap)) {
break;
}
}
@@ -504,7 +503,7 @@ getsel(void)
{
char *str, *ptr;
int y, bufsize, lastx, linelen;
- Glyph *gp, *last;
+ Letter *gp, *last;
if (sel.ob.x == -1)
return NULL;
@@ -519,7 +518,7 @@ getsel(void)
continue;
}
- if (sel.type == SEL_RECTANGULAR) {
+ if (sel.type == SelRectangular) {
gp = &term.line[y][sel.nb.x];
lastx = sel.ne.x;
} else {
@@ -531,7 +530,7 @@ getsel(void)
--last;
for ( ; gp <= last; ++gp) {
- if (gp->mode & ATTR_WDUMMY)
+ if (gp->mode & Gwdummy)
continue;
ptr += utf8·runetobyte(ptr, &gp->u);
@@ -547,7 +546,7 @@ getsel(void)
* FIXME: Fix the computer world.
*/
if ((y < sel.ne.y || lastx >= linelen) &&
- (!(last->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
+ (!(last->mode & Gwrap) || sel.type == SelRectangular))
*ptr++ = '\n';
}
*ptr = 0;
@@ -559,7 +558,7 @@ selclear(void)
{
if (sel.ob.x == -1)
return;
- sel.mode = SEL_IDLE;
+ sel.mode = SelIdle;
sel.ob.x = -1;
tsetdirt(sel.nb.y, sel.ne.y);
}
@@ -676,7 +675,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
int m, s;
if (out) {
- term.mode |= MODE_PRINT;
+ term.mode |= Tprint;
iofd = (!strcmp(out, "-")) ?
1 : open(out, O_WRONLY | O_CREAT, 0666);
if (iofd < 0) {
@@ -762,10 +761,10 @@ ttywrite(char *s, size_t n, int may_echo)
{
char *next;
- if (may_echo && IS_SET(MODE_ECHO))
+ if (may_echo && IS_SET(Techo))
twrite(s, n, 1);
- if (!IS_SET(MODE_CRLF)) {
+ if (!IS_SET(Tcrlf)) {
ttywriteraw(s, n);
return;
}
@@ -914,11 +913,11 @@ void
tcursor(int mode)
{
static TCursor c[2];
- int alt = IS_SET(MODE_ALTSCREEN);
+ int alt = IS_SET(Taltscreen);
- if (mode == CURSOR_SAVE) {
+ if (mode == CursorSave) {
c[alt] = term.c;
- } else if (mode == CURSOR_LOAD) {
+ } else if (mode == CursorLoad) {
term.c = c[alt];
tmoveto(c[alt].x, c[alt].y);
}
@@ -930,23 +929,23 @@ treset(void)
uint i;
term.c = (TCursor){{
- .mode = ATTR_NULL,
+ .mode = Gnil,
.fg = defaultfg,
.bg = defaultbg
- }, .x = 0, .y = 0, .state = CURSOR_DEFAULT};
+ }, .x = 0, .y = 0, .state = CursorDefault};
memset(term.tabs, 0, term.col * sizeof(*term.tabs));
for (i = tabspaces; i < term.col; i += tabspaces)
term.tabs[i] = 1;
term.top = 0;
term.bot = term.row - 1;
- term.mode = MODE_WRAP|MODE_UTF8;
- memset(term.trantbl, CS_USA, sizeof(term.trantbl));
+ term.mode = Twrap|Tutf8;
+ memset(term.trantbl, CSusa, sizeof(term.trantbl));
term.charset = 0;
for (i = 0; i < 2; i++) {
tmoveto(0, 0);
- tcursor(CURSOR_SAVE);
+ tcursor(CursorSave);
tclearregion(0, 0, term.col-1, term.row-1);
tswapscreen();
}
@@ -967,7 +966,7 @@ tswapscreen(void)
term.line = term.alt;
term.alt = tmp;
- term.mode ^= MODE_ALTSCREEN;
+ term.mode ^= Taltscreen;
tfulldirt();
}
@@ -1078,7 +1077,7 @@ csiparse(void)
void
tmoveato(int x, int y)
{
- tmoveto(x, y + ((term.c.state & CURSOR_ORIGIN) ? term.top: 0));
+ tmoveto(x, y + ((term.c.state & CursorOrigin) ? term.top: 0));
}
void
@@ -1086,20 +1085,20 @@ tmoveto(int x, int y)
{
int miny, maxy;
- if (term.c.state & CURSOR_ORIGIN) {
+ if (term.c.state & CursorOrigin) {
miny = term.top;
maxy = term.bot;
} else {
miny = 0;
maxy = term.row - 1;
}
- term.c.state &= ~CURSOR_WRAPNEXT;
+ term.c.state &= ~CursorWrap;
term.c.x = LIMIT(x, 0, term.col-1);
term.c.y = LIMIT(y, miny, maxy);
}
void
-tsetchar(rune u, Glyph *attr, int x, int y)
+tsetchar(rune u, Letter *attr, int x, int y)
{
static char *vt100_0[62] = { /* 0x41 - 0x7e */
"↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */
@@ -1115,18 +1114,18 @@ tsetchar(rune u, Glyph *attr, int x, int y)
/*
* The table is proudly stolen from rxvt.
*/
- if (term.trantbl[term.charset] == CS_GRAPHIC0 &&
+ if (term.trantbl[term.charset] == CSgfx0 &&
BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41])
utf8·bytetorune(&u, vt100_0[u - 0x41]);
- if (term.line[y][x].mode & ATTR_WIDE) {
+ if (term.line[y][x].mode & Gwide) {
if (x+1 < term.col) {
term.line[y][x+1].u = ' ';
- term.line[y][x+1].mode &= ~ATTR_WDUMMY;
+ term.line[y][x+1].mode &= ~Gwdummy;
}
- } else if (term.line[y][x].mode & ATTR_WDUMMY) {
+ } else if (term.line[y][x].mode & Gwdummy) {
term.line[y][x-1].u = ' ';
- term.line[y][x-1].mode &= ~ATTR_WIDE;
+ term.line[y][x-1].mode &= ~Gwide;
}
term.dirty[y] = 1;
@@ -1138,7 +1137,7 @@ void
tclearregion(int x1, int y1, int x2, int y2)
{
int x, y, temp;
- Glyph *gp;
+ Letter *gp;
if (x1 > x2)
temp = x1, x1 = x2, x2 = temp;
@@ -1168,7 +1167,7 @@ void
tdeletechar(int n)
{
int dst, src, size;
- Glyph *line;
+ Letter *line;
LIMIT(n, 0, term.col - term.c.x);
@@ -1177,7 +1176,7 @@ tdeletechar(int n)
size = term.col - src;
line = term.line[term.c.y];
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
+ memmove(&line[dst], &line[src], size * sizeof(Letter));
tclearregion(term.col-n, term.c.y, term.col-1, term.c.y);
}
@@ -1185,7 +1184,7 @@ void
tinsertblank(int n)
{
int dst, src, size;
- Glyph *line;
+ Letter *line;
LIMIT(n, 0, term.col - term.c.x);
@@ -1194,7 +1193,7 @@ tinsertblank(int n)
size = term.col - dst;
line = term.line[term.c.y];
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
+ memmove(&line[dst], &line[src], size * sizeof(Letter));
tclearregion(src, term.c.y, dst - 1, term.c.y);
}
@@ -1272,63 +1271,63 @@ tsetattr(int *attr, int l)
switch (attr[i]) {
case 0:
term.c.attr.mode &= ~(
- ATTR_BOLD |
- ATTR_FAINT |
- ATTR_ITALIC |
- ATTR_UNDERLINE |
- ATTR_BLINK |
- ATTR_REVERSE |
- ATTR_INVISIBLE |
- ATTR_STRUCK );
+ Gbold |
+ Gfaint |
+ Gitalic |
+ Gunline |
+ Gblink |
+ Greverse |
+ Ginvisible |
+ Gstruck );
term.c.attr.fg = defaultfg;
term.c.attr.bg = defaultbg;
break;
case 1:
- term.c.attr.mode |= ATTR_BOLD;
+ term.c.attr.mode |= Gbold;
break;
case 2:
- term.c.attr.mode |= ATTR_FAINT;
+ term.c.attr.mode |= Gfaint;
break;
case 3:
- term.c.attr.mode |= ATTR_ITALIC;
+ term.c.attr.mode |= Gitalic;
break;
case 4:
- term.c.attr.mode |= ATTR_UNDERLINE;
+ term.c.attr.mode |= Gunline;
break;
case 5: /* slow blink */
/* FALLTHROUGH */
case 6: /* rapid blink */
- term.c.attr.mode |= ATTR_BLINK;
+ term.c.attr.mode |= Gblink;
break;
case 7:
- term.c.attr.mode |= ATTR_REVERSE;
+ term.c.attr.mode |= Greverse;
break;
case 8:
- term.c.attr.mode |= ATTR_INVISIBLE;
+ term.c.attr.mode |= Ginvisible;
break;
case 9:
- term.c.attr.mode |= ATTR_STRUCK;
+ term.c.attr.mode |= Gstruck;
break;
case 22:
- term.c.attr.mode &= ~(ATTR_BOLD | ATTR_FAINT);
+ term.c.attr.mode &= ~(Gbold | Gfaint);
break;
case 23:
- term.c.attr.mode &= ~ATTR_ITALIC;
+ term.c.attr.mode &= ~Gitalic;
break;
case 24:
- term.c.attr.mode &= ~ATTR_UNDERLINE;
+ term.c.attr.mode &= ~Gunline;
break;
case 25:
- term.c.attr.mode &= ~ATTR_BLINK;
+ term.c.attr.mode &= ~Gblink;
break;
case 27:
- term.c.attr.mode &= ~ATTR_REVERSE;
+ term.c.attr.mode &= ~Greverse;
break;
case 28:
- term.c.attr.mode &= ~ATTR_INVISIBLE;
+ term.c.attr.mode &= ~Ginvisible;
break;
case 29:
- term.c.attr.mode &= ~ATTR_STRUCK;
+ term.c.attr.mode &= ~Gstruck;
break;
case 38:
if ((idx = tdefcolor(attr, &i, l)) >= 0)
@@ -1389,17 +1388,17 @@ tsetmode(int priv, int set, int *args, int narg)
if (priv) {
switch (*args) {
case 1: /* DECCKM -- Cursor key */
- xsetmode(set, MODE_APPCURSOR);
+ xsetmode(set, Wappcursor);
break;
case 5: /* DECSCNM -- Reverse video */
- xsetmode(set, MODE_REVERSE);
+ xsetmode(set, Wreverse);
break;
case 6: /* DECOM -- Origin */
- MODBIT(term.c.state, set, CURSOR_ORIGIN);
+ MODBIT(term.c.state, set, CursorOrigin);
tmoveato(0, 0);
break;
case 7: /* DECAWM -- Auto wrap */
- MODBIT(term.mode, set, MODE_WRAP);
+ MODBIT(term.mode, set, Twrap);
break;
case 0: /* Error (IGNORED) */
case 2: /* DECANM -- ANSI/VT52 (IGNORED) */
@@ -1412,47 +1411,47 @@ tsetmode(int priv, int set, int *args, int narg)
case 12: /* att610 -- Start blinking cursor (IGNORED) */
break;
case 25: /* DECTCEM -- Text Cursor Enable Mode */
- xsetmode(!set, MODE_HIDE);
+ xsetmode(!set, Whide);
break;
case 9: /* X10 mouse compatibility mode */
xsetpointermotion(0);
- xsetmode(0, MODE_MOUSE);
- xsetmode(set, MODE_MOUSEX10);
+ xsetmode(0, Wmouse);
+ xsetmode(set, Wmousex10);
break;
case 1000: /* 1000: report button press */
xsetpointermotion(0);
- xsetmode(0, MODE_MOUSE);
- xsetmode(set, MODE_MOUSEBTN);
+ xsetmode(0, Wmouse);
+ xsetmode(set, Wmousebtn);
break;
case 1002: /* 1002: report motion on button press */
xsetpointermotion(0);
- xsetmode(0, MODE_MOUSE);
- xsetmode(set, MODE_MOUSEMOTION);
+ xsetmode(0, Wmouse);
+ xsetmode(set, Wmousemotion);
break;
case 1003: /* 1003: enable all mouse motions */
xsetpointermotion(set);
- xsetmode(0, MODE_MOUSE);
- xsetmode(set, MODE_MOUSEMANY);
+ xsetmode(0, Wmouse);
+ xsetmode(set, Wmousemany);
break;
case 1004: /* 1004: send focus events to tty */
- xsetmode(set, MODE_FOCUS);
+ xsetmode(set, Wfocus);
break;
case 1006: /* 1006: extended reporting mode */
- xsetmode(set, MODE_MOUSESGR);
+ xsetmode(set, Wmousesgr);
break;
case 1034:
- xsetmode(set, MODE_8BIT);
+ xsetmode(set, W8bit);
break;
case 1049: /* swap screen & set/restore cursor as xterm */
if (!allowaltscreen)
break;
- tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
+ tcursor((set) ? CursorSave : CursorLoad);
/* FALLTHROUGH */
case 47: /* swap screen */
case 1047:
if (!allowaltscreen)
break;
- alt = IS_SET(MODE_ALTSCREEN);
+ alt = IS_SET(Taltscreen);
if (alt) {
tclearregion(0, 0, term.col-1,
term.row-1);
@@ -1463,10 +1462,10 @@ tsetmode(int priv, int set, int *args, int narg)
break;
/* FALLTHROUGH */
case 1048:
- tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
+ tcursor((set) ? CursorSave : CursorLoad);
break;
case 2004: /* 2004: bracketed paste mode */
- xsetmode(set, MODE_BRCKTPASTE);
+ xsetmode(set, Wbrcktpaste);
break;
/* Not implemented mouse modes. See comments there. */
case 1001: /* mouse highlight mode; can hang the
@@ -1489,16 +1488,16 @@ tsetmode(int priv, int set, int *args, int narg)
case 0: /* Error (IGNORED) */
break;
case 2:
- xsetmode(set, MODE_KBDLOCK);
+ xsetmode(set, Wkbdblock);
break;
case 4: /* IRM -- Insertion-replacement */
- MODBIT(term.mode, set, MODE_INSERT);
+ MODBIT(term.mode, set, Tinsert);
break;
case 12: /* SRM -- Send/Receive */
- MODBIT(term.mode, !set, MODE_ECHO);
+ MODBIT(term.mode, !set, Techo);
break;
case 20: /* LNM -- Linefeed/new line */
- MODBIT(term.mode, set, MODE_CRLF);
+ MODBIT(term.mode, set, Tcrlf);
break;
default:
fprintf(stderr,
@@ -1548,10 +1547,10 @@ csihandle(void)
tdumpsel();
break;
case 4:
- term.mode &= ~MODE_PRINT;
+ term.mode &= ~Tprint;
break;
case 5:
- term.mode |= MODE_PRINT;
+ term.mode |= Tprint;
break;
}
break;
@@ -1704,10 +1703,10 @@ csihandle(void)
}
break;
case 's': /* DECSC -- Save cursor position (ANSI.SYS) */
- tcursor(CURSOR_SAVE);
+ tcursor(CursorSave);
break;
case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */
- tcursor(CURSOR_LOAD);
+ tcursor(CursorLoad);
break;
case ' ':
switch (csiescseq.mode[1]) {
@@ -1758,7 +1757,7 @@ strhandle(void)
char *p = NULL, *dec;
int j, narg, par;
- term.esc &= ~(ESC_STR_END|ESC_STR);
+ term.esc &= ~(Xstrend|Xstr);
strparse();
par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0;
@@ -1808,7 +1807,7 @@ strhandle(void)
xsettitle(strescseq.args[0]);
return;
case 'P': /* DCS -- Device Control String */
- term.mode |= ESC_DCS;
+ term.mode |= Xdcs;
case '_': /* APC -- Application Program Command */
case '^': /* PM -- Privacy Message */
return;
@@ -1896,7 +1895,7 @@ tprinter(char *s, size_t len)
void
toggleprinter(Arg *arg)
{
- term.mode ^= MODE_PRINT;
+ term.mode ^= Tprint;
}
void
@@ -1926,7 +1925,7 @@ void
tdumpline(int n)
{
char buf[UTFmax];
- Glyph *bp, *end;
+ Letter *bp, *end;
bp = &term.line[n][0];
end = &bp[MIN(tlinelen(n), term.col) - 1];
@@ -1967,16 +1966,16 @@ void
tdefutf8(char ascii)
{
if (ascii == 'G')
- term.mode |= MODE_UTF8;
+ term.mode |= Tutf8;
else if (ascii == '@')
- term.mode &= ~MODE_UTF8;
+ term.mode &= ~Tutf8;
}
void
tdeftran(char ascii)
{
static char cs[] = "0B";
- static int vcs[] = {CS_GRAPHIC0, CS_USA};
+ static int vcs[] = {CSgfx0, CSusa};
char *p;
if ((p = strchr(cs, ascii)) == NULL) {
@@ -2007,7 +2006,7 @@ tstrsequence(uchar c)
switch (c) {
case 0x90: /* DCS -- Device Control String */
c = 'P';
- term.esc |= ESC_DCS;
+ term.esc |= Xdcs;
break;
case 0x9f: /* APC -- Application Program Command */
c = '_';
@@ -2020,7 +2019,7 @@ tstrsequence(uchar c)
break;
}
strescseq.type = c;
- term.esc |= ESC_STR;
+ term.esc |= Xstr;
}
void
@@ -2040,10 +2039,10 @@ tcontrolcode(uchar ascii)
case '\v': /* VT */
case '\n': /* LF */
/* go to first col if the mode is set */
- tnewline(IS_SET(MODE_CRLF));
+ tnewline(IS_SET(Tcrlf));
return;
case '\a': /* BEL */
- if (term.esc & ESC_STR_END) {
+ if (term.esc & Xstrend) {
/* backwards compatibility to xterm */
strhandle();
} else {
@@ -2052,8 +2051,8 @@ tcontrolcode(uchar ascii)
break;
case '\033': /* ESC */
csireset();
- term.esc &= ~(ESC_CSI|ESC_ALTCHARSET|ESC_TEST);
- term.esc |= ESC_START;
+ term.esc &= ~(Xcsi|Xaltcs|Xtest);
+ term.esc |= Xstart;
return;
case '\016': /* SO (LS1 -- Locking shift 1) */
case '\017': /* SI (LS0 -- Locking shift 0) */
@@ -2117,7 +2116,7 @@ tcontrolcode(uchar ascii)
return;
}
/* only CAN, SUB, \a and C1 chars interrupt a sequence */
- term.esc &= ~(ESC_STR_END|ESC_STR);
+ term.esc &= ~(Xstrend|Xstr);
}
/*
@@ -2129,13 +2128,13 @@ eschandle(uchar ascii)
{
switch (ascii) {
case '[':
- term.esc |= ESC_CSI;
+ term.esc |= Xcsi;
return 0;
case '#':
- term.esc |= ESC_TEST;
+ term.esc |= Xtest;
return 0;
case '%':
- term.esc |= ESC_UTF8;
+ term.esc |= Xutf8;
return 0;
case 'P': /* DCS -- Device Control String */
case '_': /* APC -- Application Program Command */
@@ -2153,7 +2152,7 @@ eschandle(uchar ascii)
case '*': /* G2D4 -- set tertiary charset G2 */
case '+': /* G3D4 -- set quaternary charset G3 */
term.icharset = ascii - '(';
- term.esc |= ESC_ALTCHARSET;
+ term.esc |= Xaltcs;
return 0;
case 'D': /* IND -- Linefeed */
if (term.c.y == term.bot) {
@@ -2184,19 +2183,19 @@ eschandle(uchar ascii)
xloadcols();
break;
case '=': /* DECPAM -- Application keypad */
- xsetmode(1, MODE_APPKEYPAD);
+ xsetmode(1, Wappkeypad);
break;
case '>': /* DECPNM -- Normal keypad */
- xsetmode(0, MODE_APPKEYPAD);
+ xsetmode(0, Wappkeypad);
break;
case '7': /* DECSC -- Save Cursor */
- tcursor(CURSOR_SAVE);
+ tcursor(CursorSave);
break;
case '8': /* DECRC -- Restore Cursor */
- tcursor(CURSOR_LOAD);
+ tcursor(CursorLoad);
break;
case '\\': /* ST -- String Terminator */
- if (term.esc & ESC_STR_END)
+ if (term.esc & Xstrend)
strhandle();
break;
default:
@@ -2213,10 +2212,10 @@ tputc(rune u)
char c[UTFmax];
int control;
int width, len;
- Glyph *gp;
+ Letter *gp;
control = ISCONTROL(u);
- if (u < 127 || !IS_SET(MODE_UTF8 | MODE_SIXEL)) {
+ if (u < 127 || !IS_SET(Tutf8 | Tsixel)) {
c[0] = u;
width = len = 1;
} else {
@@ -2225,7 +2224,7 @@ tputc(rune u)
width = 1;
}
- if (IS_SET(MODE_PRINT))
+ if (IS_SET(Tprint))
tprinter(c, len);
/*
@@ -2234,25 +2233,25 @@ tputc(rune u)
* receives a ESC, a SUB, a ST or any other C1 control
* character.
*/
- if (term.esc & ESC_STR) {
+ if (term.esc & Xstr) {
if (u == '\a' || u == 030 || u == 032 || u == 033 ||
ISCONTROLC1(u)) {
- term.esc &= ~(ESC_START|ESC_STR|ESC_DCS);
- if (IS_SET(MODE_SIXEL)) {
+ term.esc &= ~(Xstart|Xstr|Xdcs);
+ if (IS_SET(Tsixel)) {
/* TODO: render sixel */;
- term.mode &= ~MODE_SIXEL;
+ term.mode &= ~Tsixel;
return;
}
- term.esc |= ESC_STR_END;
+ term.esc |= Xstrend;
goto check_control_code;
}
- if (IS_SET(MODE_SIXEL)) {
+ if (IS_SET(Tsixel)) {
/* TODO: implement sixel mode */
return;
}
- if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
- term.mode |= MODE_SIXEL;
+ if (term.esc&Xdcs && strescseq.len == 0 && u == 'q')
+ term.mode |= Tsixel;
if (strescseq.len+len >= strescseq.siz) {
/*
@@ -2293,8 +2292,8 @@ check_control_code:
if (!term.esc)
term.lastc = 0;
return;
- } else if (term.esc & ESC_START) {
- if (term.esc & ESC_CSI) {
+ } else if (term.esc & Xstart) {
+ if (term.esc & Xcsi) {
csiescseq.buf[csiescseq.len++] = u;
if (BETWEEN(u, 0x40, 0x7E)
|| csiescseq.len >= \
@@ -2304,11 +2303,11 @@ check_control_code:
csihandle();
}
return;
- } else if (term.esc & ESC_UTF8) {
+ } else if (term.esc & Xutf8) {
tdefutf8(u);
- } else if (term.esc & ESC_ALTCHARSET) {
+ } else if (term.esc & Xaltcs) {
tdeftran(u);
- } else if (term.esc & ESC_TEST) {
+ } else if (term.esc & Xtest) {
tdectest(u);
} else {
if (!eschandle(u))
@@ -2326,14 +2325,14 @@ check_control_code:
selclear();
gp = &term.line[term.c.y][term.c.x];
- if (IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
- gp->mode |= ATTR_WRAP;
+ if (IS_SET(Twrap) && (term.c.state & CursorWrap)) {
+ gp->mode |= Gwrap;
tnewline(1);
gp = &term.line[term.c.y][term.c.x];
}
- if (IS_SET(MODE_INSERT) && term.c.x+width < term.col)
- memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph));
+ if (IS_SET(Tinsert) && term.c.x+width < term.col)
+ memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Letter));
if (term.c.x+width > term.col) {
tnewline(1);
@@ -2344,16 +2343,16 @@ check_control_code:
term.lastc = u;
if (width == 2) {
- gp->mode |= ATTR_WIDE;
+ gp->mode |= Gwrap;
if (term.c.x+1 < term.col) {
gp[1].u = '\0';
- gp[1].mode = ATTR_WDUMMY;
+ gp[1].mode = Gwdummy;
}
}
if (term.c.x+width < term.col) {
tmoveto(term.c.x+width, term.c.y);
} else {
- term.c.state |= CURSOR_WRAPNEXT;
+ term.c.state |= CursorWrap;
}
}
@@ -2365,7 +2364,7 @@ twrite(char *buf, int buflen, int show_ctrl)
int n;
for (n = 0; n < buflen; n += charsize) {
- if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
+ if (IS_SET(Tutf8) && !IS_SET(Tsixel)) {
/* process a complete utf8 char */
charsize = utf8·bytetorune(&u, buf + n);
if (charsize == 0)
@@ -2431,14 +2430,14 @@ tresize(int col, int row)
/* resize each row to new width, zero-pad if needed */
for (i = 0; i < minrow; i++) {
- term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
- term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph));
+ term.line[i] = xrealloc(term.line[i], col * sizeof(Letter));
+ term.alt[i] = xrealloc(term.alt[i], col * sizeof(Letter));
}
/* allocate any new rows */
for (/* i = minrow */; i < row; i++) {
- term.line[i] = xmalloc(col * sizeof(Glyph));
- term.alt[i] = xmalloc(col * sizeof(Glyph));
+ term.line[i] = xmalloc(col * sizeof(Letter));
+ term.alt[i] = xmalloc(col * sizeof(Letter));
}
if (col > term.col) {
bp = term.tabs + term.col;
@@ -2466,7 +2465,7 @@ tresize(int col, int row)
tclearregion(0, minrow, col - 1, row - 1);
}
tswapscreen();
- tcursor(CURSOR_LOAD);
+ tcursor(CursorLoad);
}
term.c = c;
}
@@ -2502,9 +2501,9 @@ draw(void)
/* adjust cursor position */
LIMIT(term.ocx, 0, term.col-1);
LIMIT(term.ocy, 0, term.row-1);
- if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY)
+ if (term.line[term.ocy][term.ocx].mode & Gwdummy)
term.ocx--;
- if (term.line[term.c.y][cx].mode & ATTR_WDUMMY)
+ if (term.line[term.c.y][cx].mode & Gwdummy)
cx--;
drawregion(0, 0, term.col, term.row);