aboutsummaryrefslogtreecommitdiff
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
parent7b5b105d84103d4320de510f0fdab345b5d2f477 (diff)
changed all caps
-rw-r--r--sys/cmd/term/arg.h50
-rw-r--r--sys/cmd/term/config.h2
-rw-r--r--sys/cmd/term/term.c535
-rw-r--r--sys/cmd/term/term.h108
-rw-r--r--sys/cmd/term/win.h39
-rw-r--r--sys/cmd/term/x.c155
6 files changed, 423 insertions, 466 deletions
diff --git a/sys/cmd/term/arg.h b/sys/cmd/term/arg.h
deleted file mode 100644
index a22e019..0000000
--- a/sys/cmd/term/arg.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copy me if you can.
- * by 20h
- */
-
-#ifndef ARG_H__
-#define ARG_H__
-
-extern char *argv0;
-
-/* use main(int argc, char *argv[]) */
-#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
- argv[0] && argv[0][0] == '-'\
- && argv[0][1];\
- argc--, argv++) {\
- char argc_;\
- char **argv_;\
- int brk_;\
- if (argv[0][1] == '-' && argv[0][2] == '\0') {\
- argv++;\
- argc--;\
- break;\
- }\
- int i_;\
- for (i_ = 1, brk_ = 0, argv_ = argv;\
- argv[0][i_] && !brk_;\
- i_++) {\
- if (argv_ != argv)\
- break;\
- argc_ = argv[0][i_];\
- switch (argc_)
-
-#define ARGEND }\
- }
-
-#define ARGC() argc_
-
-#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
- ((x), abort(), (char *)0) :\
- (brk_ = 1, (argv[0][i_+1] != '\0')?\
- (&argv[0][i_+1]) :\
- (argc--, argv++, argv[0])))
-
-#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
- (char *)0 :\
- (brk_ = 1, (argv[0][i_+1] != '\0')?\
- (&argv[0][i_+1]) :\
- (argc--, argv++, argv[0])))
-
-#endif
diff --git a/sys/cmd/term/config.h b/sys/cmd/term/config.h
index 54aa641..a195786 100644
--- a/sys/cmd/term/config.h
+++ b/sys/cmd/term/config.h
@@ -460,7 +460,7 @@ static Key key[] = {
* If no match is found, regular selection is used.
*/
static uint selmasks[] = {
- [SEL_RECTANGULAR] = Mod1Mask,
+ [SelRectangular] = Mod1Mask,
};
/*
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);
diff --git a/sys/cmd/term/term.h b/sys/cmd/term/term.h
index 0272f25..62c407f 100644
--- a/sys/cmd/term/term.h
+++ b/sys/cmd/term/term.h
@@ -11,12 +11,14 @@
#include <sys/types.h>
#include <sys/wait.h>
-/* macros */
+// -----------------------------------------------------------------------
+// macros
+
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
-#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
+#define GLYPHCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
(a).bg != (b).bg)
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
(t1.tv_nsec-t2.tv_nsec)/1E6)
@@ -25,47 +27,78 @@
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
#define IS_TRUECOL(x) (1 << 24 & (x))
-enum glyph_attribute {
- ATTR_NULL = 0,
- ATTR_BOLD = 1 << 0,
- ATTR_FAINT = 1 << 1,
- ATTR_ITALIC = 1 << 2,
- ATTR_UNDERLINE = 1 << 3,
- ATTR_BLINK = 1 << 4,
- ATTR_REVERSE = 1 << 5,
- ATTR_INVISIBLE = 1 << 6,
- ATTR_STRUCK = 1 << 7,
- ATTR_WRAP = 1 << 8,
- ATTR_WIDE = 1 << 9,
- ATTR_WDUMMY = 1 << 10,
- ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
+#define iota(x) 1 << (x)
+
+// -----------------------------------------------------------------------
+// constants
+
+enum {
+ Gnil,
+ Gbold = iota(0),
+ Gfaint = iota(1),
+ Gitalic = iota(2),
+ Gunline = iota(3),
+ Gblink = iota(4),
+ Greverse = iota(5),
+ Ginvisible = iota(6),
+ Gstruck = iota(7),
+ Gwrap = iota(8),
+ Gwide = iota(9),
+ Gwdummy = iota(10),
+ Gboldfaint = Gbold | Gfaint,
+};
+
+enum {
+ SelIdle = 0,
+ SelEmpty = 1,
+ SelReady = 2
};
-enum selection_mode {
- SEL_IDLE = 0,
- SEL_EMPTY = 1,
- SEL_READY = 2
+enum {
+ SelRegular = 1,
+ SelRectangular = 2
};
-enum selection_type {
- SEL_REGULAR = 1,
- SEL_RECTANGULAR = 2
+enum {
+ SnapWord = 1,
+ SnapLine = 2
};
-enum selection_snap {
- SNAP_WORD = 1,
- SNAP_LINE = 2
+enum win_mode {
+ Wvisible = 1 << 0,
+ Wfocused = 1 << 1,
+ Wappkeypad = 1 << 2,
+ Wmousebtn = 1 << 3,
+ Wmousemotion = 1 << 4,
+ Wreverse = 1 << 5,
+ Wkbdblock = 1 << 6,
+ Whide = 1 << 7,
+ Wappcursor = 1 << 8,
+ Wmousesgr = 1 << 9,
+ W8bit = 1 << 10,
+ Wblink = 1 << 11,
+ Wbflink = 1 << 12,
+ Wfocus = 1 << 13,
+ Wmousex10 = 1 << 14,
+ Wmousemany = 1 << 15,
+ Wbrcktpaste = 1 << 16,
+ Wnumlock = 1 << 17,
+ Wmouse = Wmousebtn|Wmousemotion|Wmousex10|Wmousemany,
};
-#define Glyph Glyph_
-typedef struct {
+
+// -----------------------------------------------------------------------
+// types
+typedef struct Letter Letter;
+
+struct Letter {
rune u; /* character code */
ushort mode; /* attribute flags */
uint32_t fg; /* foreground */
uint32_t bg; /* background */
-} Glyph;
+};
-typedef Glyph *Line;
+typedef Letter *Line;
typedef union {
int i;
@@ -75,6 +108,21 @@ typedef union {
char *s;
} Arg;
+void xbell(void);
+void xclipcopy(void);
+void xdrawcursor(int, int, Letter, int, int, Letter);
+void xdrawline(Line, int, int, int);
+void xfinishdraw(void);
+void xloadcols(void);
+int xsetcolorname(int, char *);
+void xsettitle(char *);
+int xsetcursor(int);
+void xsetmode(int, uint);
+void xsetpointermotion(int);
+void xsetsel(char *);
+int xstartdraw(void);
+void xximspot(int, int);
+
void die( char *, ...);
void redraw(void);
void draw(void);
diff --git a/sys/cmd/term/win.h b/sys/cmd/term/win.h
deleted file mode 100644
index 7202ef3..0000000
--- a/sys/cmd/term/win.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* See LICENSE for license details. */
-
-enum win_mode {
- MODE_VISIBLE = 1 << 0,
- MODE_FOCUSED = 1 << 1,
- MODE_APPKEYPAD = 1 << 2,
- MODE_MOUSEBTN = 1 << 3,
- MODE_MOUSEMOTION = 1 << 4,
- MODE_REVERSE = 1 << 5,
- MODE_KBDLOCK = 1 << 6,
- MODE_HIDE = 1 << 7,
- MODE_APPCURSOR = 1 << 8,
- MODE_MOUSESGR = 1 << 9,
- MODE_8BIT = 1 << 10,
- MODE_BLINK = 1 << 11,
- MODE_FBLINK = 1 << 12,
- MODE_FOCUS = 1 << 13,
- MODE_MOUSEX10 = 1 << 14,
- MODE_MOUSEMANY = 1 << 15,
- MODE_BRCKTPASTE = 1 << 16,
- MODE_NUMLOCK = 1 << 17,
- MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
- |MODE_MOUSEMANY,
-};
-
-void xbell(void);
-void xclipcopy(void);
-void xdrawcursor(int, int, Glyph, int, int, Glyph);
-void xdrawline(Line, int, int, int);
-void xfinishdraw(void);
-void xloadcols(void);
-int xsetcolorname(int, char *);
-void xsettitle(char *);
-int xsetcursor(int);
-void xsetmode(int, uint);
-void xsetpointermotion(int);
-void xsetsel(char *);
-int xstartdraw(void);
-void xximspot(int, int);
diff --git a/sys/cmd/term/x.c b/sys/cmd/term/x.c
index 9e0327c..129d639 100644
--- a/sys/cmd/term/x.c
+++ b/sys/cmd/term/x.c
@@ -10,22 +10,21 @@
#include <X11/XKBlib.h>
#include "term.h"
-#include "win.h"
/* types used in config.h */
typedef struct {
- uint mod;
+ uint mod;
KeySym keysym;
void (*func)(Arg *);
- Arg arg;
+ Arg arg;
} Shortcut;
typedef struct {
uint mod;
uint button;
void (*func)(Arg *);
- Arg arg;
- uint release;
+ Arg arg;
+ uint release;
} MouseShortcut;
typedef struct {
@@ -133,9 +132,9 @@ typedef struct {
} DC;
static inline ushort sixd_to_16bit(int);
-static int xmakeglyphfontspecs(XftGlyphFontSpec *, Glyph *, int, int, int);
-static void xdrawglyphfontspecs(XftGlyphFontSpec *, Glyph, int, int, int);
-static void xdrawglyph(Glyph, int, int);
+static int xmakeglyphfontspecs(XftGlyphFontSpec *, Letter *, int, int, int);
+static void xdrawglyphfontspecs(XftGlyphFontSpec *, Letter, int, int, int);
+static void xdrawglyph(Letter, int, int);
static void xclear(int, int, int, int);
static int xgeommasktogravity(int);
static int ximopen(Display *);
@@ -281,7 +280,7 @@ selpaste(Arg *_)
void
numlock(Arg *_)
{
- win.mode ^= MODE_NUMLOCK;
+ win.mode ^= Wnumlock;
}
void
@@ -339,7 +338,7 @@ evrow(XEvent *e)
void
mousesel(XEvent *e, int done)
{
- int type, seltype = SEL_REGULAR;
+ int type, seltype = SelRegular;
uint state = e->xbutton.state & ~(Button1Mask | forcemousemod);
for (type = 1; type < arrlen(selmasks); ++type) {
@@ -365,17 +364,17 @@ mousereport(XEvent *e)
if (e->xbutton.type == MotionNotify) {
if (x == ox && y == oy)
return;
- if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
+ if (!IS_SET(Wmousemotion) && !IS_SET(Wmousemany))
return;
/* MOUSE_MOTION: no reporting if no button is pressed */
- if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
+ if (IS_SET(Wmousemotion) && oldbutton == 3)
return;
button = oldbutton + 32;
ox = x;
oy = y;
} else {
- if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
+ if (!IS_SET(Wmousesgr) && e->xbutton.type == ButtonRelease) {
button = 3;
} else {
button -= Button1;
@@ -388,21 +387,21 @@ mousereport(XEvent *e)
oy = y;
} else if (e->xbutton.type == ButtonRelease) {
oldbutton = 3;
- /* MODE_MOUSEX10: no button release reporting */
- if (IS_SET(MODE_MOUSEX10))
+ /* Wmousex10: no button release reporting */
+ if (IS_SET(Wmousex10))
return;
if (button == 64 || button == 65)
return;
}
}
- if (!IS_SET(MODE_MOUSEX10)) {
+ if (!IS_SET(Wmousex10)) {
button += ((state & ShiftMask ) ? 4 : 0)
+ ((state & Mod4Mask ) ? 8 : 0)
+ ((state & ControlMask) ? 16 : 0);
}
- if (IS_SET(MODE_MOUSESGR)) {
+ if (IS_SET(Wmousesgr)) {
len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
button, x+1, y+1,
e->xbutton.type == ButtonRelease ? 'm' : 'M');
@@ -454,7 +453,7 @@ bpress(XEvent *e)
struct timespec now;
int snap;
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -469,9 +468,9 @@ bpress(XEvent *e)
*/
clock_gettime(CLOCK_MONOTONIC, &now);
if (TIMEDIFF(now, xsel.tclick2) <= tripleclicktimeout) {
- snap = SNAP_LINE;
+ snap = SnapLine;
} else if (TIMEDIFF(now, xsel.tclick1) <= doubleclicktimeout) {
- snap = SNAP_WORD;
+ snap = SnapWord;
} else {
snap = 0;
}
@@ -566,10 +565,10 @@ selnotify(XEvent *e)
*repl++ = '\r';
}
- if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
+ if (IS_SET(Wbrcktpaste) && ofs == 0)
ttywrite("\033[200~", 6, 0);
ttywrite((char *)data, nitems * format / 8, 1);
- if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
+ if (IS_SET(Wbrcktpaste) && rem == 0)
ttywrite("\033[201~", 6, 0);
XFree(data);
/* number of 32-bit chunks returned */
@@ -676,7 +675,7 @@ xsetsel(char *str)
void
brelease(XEvent *e)
{
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -690,7 +689,7 @@ brelease(XEvent *e)
void
bmotion(XEvent *e)
{
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -813,7 +812,7 @@ void
xclear(int x1, int y1, int x2, int y2)
{
XftDrawRect(xw.draw,
- &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg],
+ &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg],
x1, y1, x2-x1, y2-y1);
}
@@ -1184,7 +1183,7 @@ xinit(int cols, int rows)
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
- win.mode = MODE_NUMLOCK;
+ win.mode = Wnumlock;
resettitle();
xhints();
XMapWindow(xw.dpy, xw.win);
@@ -1200,7 +1199,7 @@ xinit(int cols, int rows)
}
int
-xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int y)
+xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int y)
{
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
ushort mode, prevmode = USHRT_MAX;
@@ -1221,7 +1220,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
mode = glyphs[i].mode;
/* Skip dummy wide-character spacing. */
- if (mode == ATTR_WDUMMY)
+ if (mode == Gwdummy)
continue;
/* Determine font for glyph if different from previous glyph. */
@@ -1229,14 +1228,14 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
prevmode = mode;
font = &dc.font;
frcflags = FRC_NORMAL;
- runewidth = win.cw * ((mode & ATTR_WIDE) ? 2.0f : 1.0f);
- if ((mode & ATTR_ITALIC) && (mode & ATTR_BOLD)) {
+ runewidth = win.cw * ((mode & Gwide) ? 2.0f : 1.0f);
+ if ((mode & Gitalic) && (mode & Gbold)) {
font = &dc.ibfont;
frcflags = FRC_ITALICBOLD;
- } else if (mode & ATTR_ITALIC) {
+ } else if (mode & Gitalic) {
font = &dc.ifont;
frcflags = FRC_ITALIC;
- } else if (mode & ATTR_BOLD) {
+ } else if (mode & Gbold) {
font = &dc.bfont;
frcflags = FRC_BOLD;
}
@@ -1332,9 +1331,9 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
}
void
-xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
+xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
{
- int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
+ int charlen = len * ((base.mode & Gwide) ? 2 : 1);
int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
width = charlen * win.cw;
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
@@ -1342,11 +1341,11 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
XRectangle r;
/* Fallback on color display for attributes not supported by the font */
- if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
+ if (base.mode & Gitalic && base.mode & Gbold) {
if (dc.ibfont.badslant || dc.ibfont.badweight)
base.fg = defaultattr;
- } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) ||
- (base.mode & ATTR_BOLD && dc.bfont.badweight)) {
+ } else if ((base.mode & Gitalic && dc.ifont.badslant) ||
+ (base.mode & Gbold && dc.bfont.badweight)) {
base.fg = defaultattr;
}
@@ -1373,10 +1372,10 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
/* Change basic system colors [0-7] to bright system colors [8-15] */
- if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
+ if ((base.mode & Gfaint) == Gbold && BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
- if (IS_SET(MODE_REVERSE)) {
+ if (IS_SET(Wreverse)) {
if (fg == &dc.col[defaultfg]) {
fg = &dc.col[defaultbg];
} else {
@@ -1402,7 +1401,7 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
}
- if ((base.mode & ATTR_BOLD_FAINT) == ATTR_FAINT) {
+ if ((base.mode & Gboldfaint) == Gfaint) {
colfg.red = fg->color.red / 2;
colfg.green = fg->color.green / 2;
colfg.blue = fg->color.blue / 2;
@@ -1411,16 +1410,16 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
fg = &revfg;
}
- if (base.mode & ATTR_REVERSE) {
+ if (base.mode & Greverse) {
temp = fg;
fg = bg;
bg = temp;
}
- if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
+ if (base.mode & Gblink && win.mode & Wblink)
fg = bg;
- if (base.mode & ATTR_INVISIBLE)
+ if (base.mode & Ginvisible)
fg = bg;
/* Intelligent cleaning up of the borders. */
@@ -1452,12 +1451,12 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
/* Render underline and strikethrough. */
- if (base.mode & ATTR_UNDERLINE) {
+ if (base.mode & Gunline) {
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
width, 1);
}
- if (base.mode & ATTR_STRUCK) {
+ if (base.mode & Gstruck) {
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
width, 1);
}
@@ -1467,7 +1466,7 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
void
-xdrawglyph(Glyph g, int x, int y)
+xdrawglyph(Letter g, int x, int y)
{
int numspecs;
XftGlyphFontSpec spec;
@@ -1477,25 +1476,25 @@ xdrawglyph(Glyph g, int x, int y)
}
void
-xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
{
Color drawcol;
/* remove the old cursor */
if (selected(ox, oy))
- og.mode ^= ATTR_REVERSE;
+ og.mode ^= Greverse;
xdrawglyph(og, ox, oy);
- if (IS_SET(MODE_HIDE))
+ if (IS_SET(Whide))
return;
/*
* Select the right color for the right mode.
*/
- g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
+ g.mode &= Gbold|Gitalic|Gunline|Gstruck|Gwide;
- if (IS_SET(MODE_REVERSE)) {
- g.mode |= ATTR_REVERSE;
+ if (IS_SET(Wreverse)) {
+ g.mode |= Greverse;
g.bg = defaultfg;
if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
@@ -1516,7 +1515,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
}
/* draw the new one */
- if (IS_SET(MODE_FOCUSED)) {
+ if (IS_SET(Wfocused)) {
switch (win.cursor) {
case 7: /* st extension */
g.u = 0x2603; /* snowman (U+2603) */
@@ -1587,25 +1586,25 @@ xsettitle(char *p)
int
xstartdraw(void)
{
- return IS_SET(MODE_VISIBLE);
+ return IS_SET(Wvisible);
}
void
xdrawline(Line line, int x1, int y1, int x2)
{
int i, x, ox, numspecs;
- Glyph base, new;
+ Letter base, new;
XftGlyphFontSpec *specs = xw.specbuf;
numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) {
new = line[x];
- if (new.mode == ATTR_WDUMMY)
+ if (new.mode == Gwdummy)
continue;
if (selected(x, y1))
- new.mode ^= ATTR_REVERSE;
- if (i > 0 && ATTRCMP(base, new)) {
+ new.mode ^= Greverse;
+ if (i > 0 && GLYPHCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1);
specs += i;
numspecs -= i;
@@ -1627,7 +1626,7 @@ xfinishdraw(void)
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
win.h, 0, 0);
XSetForeground(xw.dpy, dc.gc,
- dc.col[IS_SET(MODE_REVERSE)?
+ dc.col[IS_SET(Wreverse)?
defaultfg : defaultbg].pixel);
}
@@ -1654,13 +1653,13 @@ visibility(XEvent *ev)
{
XVisibilityEvent *e = &ev->xvisibility;
- MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE);
+ MODBIT(win.mode, e->state != VisibilityFullyObscured, Wvisible);
}
void
unmap(XEvent *ev)
{
- win.mode &= ~MODE_VISIBLE;
+ win.mode &= ~Wvisible;
}
void
@@ -1675,7 +1674,7 @@ xsetmode(int set, uint flags)
{
int mode = win.mode;
MODBIT(win.mode, set, flags);
- if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE))
+ if ((win.mode & Wreverse) != (mode & Wreverse))
redraw();
}
@@ -1701,7 +1700,7 @@ xseturgency(int add)
void
xbell(void)
{
- if (!(IS_SET(MODE_FOCUSED)))
+ if (!(IS_SET(Wfocused)))
xseturgency(1);
if (bellvolume)
XkbBell(xw.dpy, xw.win, bellvolume, (Atom)nil);
@@ -1718,15 +1717,15 @@ focus(XEvent *ev)
if (ev->type == FocusIn) {
if (xw.ime.xic)
XSetICFocus(xw.ime.xic);
- win.mode |= MODE_FOCUSED;
+ win.mode |= Wfocused;
xseturgency(0);
- if (IS_SET(MODE_FOCUS))
+ if (IS_SET(Wfocus))
ttywrite("\033[I", 3, 0);
} else {
if (xw.ime.xic)
XUnsetICFocus(xw.ime.xic);
- win.mode &= ~MODE_FOCUSED;
- if (IS_SET(MODE_FOCUS))
+ win.mode &= ~Wfocused;
+ if (IS_SET(Wfocus))
ttywrite("\033[O", 3, 0);
}
}
@@ -1760,12 +1759,12 @@ kmap(KeySym k, uint state)
if (!match(kp->mask, state))
continue;
- if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
+ if (IS_SET(Wappkeypad) ? kp->appkey < 0 : kp->appkey > 0)
continue;
- if (IS_SET(MODE_NUMLOCK) && kp->appkey == 2)
+ if (IS_SET(Wnumlock) && kp->appkey == 2)
continue;
- if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
+ if (IS_SET(Wappcursor) ? kp->appcursor < 0 : kp->appcursor > 0)
continue;
return kp->s;
@@ -1785,7 +1784,7 @@ kpress(XEvent *ev)
Status status;
Shortcut *bp;
- if (IS_SET(MODE_KBDLOCK))
+ if (IS_SET(Wkbdblock))
return;
if (xw.ime.xic)
@@ -1810,7 +1809,7 @@ kpress(XEvent *ev)
if (len == 0)
return;
if (len == 1 && e->state & Mod1Mask) {
- if (IS_SET(MODE_8BIT)) {
+ if (IS_SET(W8bit)) {
if (*buf < 0177) {
c = *buf | 0x80;
len = utf8·runetobyte(buf, &c);
@@ -1833,10 +1832,10 @@ cmessage(XEvent *e)
*/
if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
- win.mode |= MODE_FOCUSED;
+ win.mode |= Wfocused;
xseturgency(0);
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
- win.mode &= ~MODE_FOCUSED;
+ win.mode &= ~Wfocused;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
ttyhangup();
@@ -1938,13 +1937,13 @@ run(void)
/* idle detected or maxlatency exhausted -> draw */
timeout = -1;
- if (blinktimeout && tattrset(ATTR_BLINK)) {
+ if (blinktimeout && tattrset(Gblink)) {
timeout = blinktimeout - TIMEDIFF(now, lastblink);
if (timeout <= 0) {
if (-timeout > blinktimeout) /* start visible */
- win.mode |= MODE_BLINK;
- win.mode ^= MODE_BLINK;
- tsetdirtattr(ATTR_BLINK);
+ win.mode |= Wblink;
+ win.mode ^= Wblink;
+ tsetdirtattr(Gblink);
lastblink = now;
timeout = blinktimeout;
}