aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/term/term.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 13:26:49 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 13:26:49 -0700
commitb3ea2b804fbd35babac86c83c718a5491542db7c (patch)
tree9d00af565805538213d06bf50cfbd5b499632495 /sys/cmd/term/term.c
parentc320322dffd8f4648cc24ab731ac64dda6eec77d (diff)
done tinkering with st
Diffstat (limited to 'sys/cmd/term/term.c')
-rw-r--r--sys/cmd/term/term.c152
1 files changed, 18 insertions, 134 deletions
diff --git a/sys/cmd/term/term.c b/sys/cmd/term/term.c
index 81dd937..aecdcb4 100644
--- a/sys/cmd/term/term.c
+++ b/sys/cmd/term/term.c
@@ -26,126 +26,11 @@
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
-/* 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),
-};
-
-/* cursor state */
-enum {
- CursorSave,
- CursorLoad
-};
-
-/* cursor mode */
-enum {
- CursorDefault = 0,
- CursorWrap = 1,
- CursorOrigin = 2
-};
-
-/* character set */
-enum {
- CSgfx0,
- CSgfx1,
- CSuk,
- CSusa,
- CSmulti,
- CSger,
- CSfin,
-};
-
-/* 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 {
- Letter attr; /* current char attributes */
- int x;
- int y;
- char state;
-} TCursor;
-
-typedef struct {
- int mode;
- int type;
- int snap;
- /*
- * Selection variables:
- * nb – normalized coordinates of the beginning of the selection
- * ne – normalized coordinates of the end of the selection
- * ob – original coordinates of the beginning of the selection
- * oe – original coordinates of the end of the selection
- */
- struct {
- int x, y;
- } nb, ne, ob, oe;
-
- int alt;
-} Selection;
-
-/* Internal representation of the screen */
-typedef struct {
- int row; /* nb row */
- int col; /* nb col */
- Line *line; /* screen */
- Line *alt; /* alternate screen */
- 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 */
- char trantbl[4]; /* charset table translation */
- int charset; /* current charset */
- int icharset; /* selected charset for sequence */
- int *tabs;
- rune lastc; /* last printed char outside of sequence, 0 if control */
-} Term;
-
-/* CSI Escape sequence structs */
-/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
-typedef struct {
- char buf[ESC_BUF_SIZ]; /* raw string */
- size_t len; /* raw string length */
- char priv;
- int arg[ESC_ARG_SIZ];
- int narg; /* nb of args */
- char mode[2];
-} CSIEscape;
-
-/* STR Escape sequence structs */
-/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
-typedef struct {
- char type; /* ESC type ... */
- char *buf; /* allocated raw string */
- size_t siz; /* allocation size */
- size_t len; /* raw string length */
- char *args[STR_ARG_SIZ];
- int narg; /* nb of args */
-} STREscape;
-
-static void execsh(char *, char **);
-static void stty(char **);
-static void sigchld(int);
-static void ttywriteraw(char *, size_t);
+/* forward declare functions */
+static void execsh(char *, char **);
+static void stty(char **);
+static void sigchld(int);
+static void ttywriteraw(char *, size_t);
static void csidump(void);
static void csihandle(void);
@@ -201,11 +86,10 @@ static char *base64dec(char *);
static char base64dec_getc(char **);
static uintptr xwrite(int, char *, size_t);
-
-extern int wcwidth(wchar_t wc);
+extern int wcwidth(wchar_t wc);
/* Globals */
-static Term term;
+static Terminal term;
static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
@@ -912,7 +796,7 @@ tfulldirt(void)
void
tcursor(int mode)
{
- static TCursor c[2];
+ static Dot c[2];
int alt = IS_SET(Taltscreen);
if (mode == CursorSave) {
@@ -928,7 +812,7 @@ treset(void)
{
uint i;
- term.c = (TCursor){{
+ term.c = (Dot){{
.mode = Gnil,
.fg = defaultfg,
.bg = defaultbg
@@ -954,7 +838,7 @@ treset(void)
void
tnew(int col, int row)
{
- term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
+ term = (Terminal){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
tresize(col, row);
treset();
}
@@ -962,7 +846,7 @@ tnew(int col, int row)
void
tswapscreen(void)
{
- Line *tmp = term.line;
+ Letter **tmp = term.line;
term.line = term.alt;
term.alt = tmp;
@@ -974,7 +858,7 @@ void
tscrolldown(int orig, int n)
{
int i;
- Line temp;
+ Letter *temp;
LIMIT(n, 0, term.bot-orig+1);
@@ -994,7 +878,7 @@ void
tscrollup(int orig, int n)
{
int i;
- Line temp;
+ Letter *temp;
LIMIT(n, 0, term.bot-orig+1);
@@ -2395,7 +2279,7 @@ tresize(int col, int row)
int minrow = MIN(row, term.row);
int mincol = MIN(col, term.col);
int *bp;
- TCursor c;
+ Dot c;
if (col < 1 || row < 1) {
fprintf(stderr,
@@ -2414,8 +2298,8 @@ tresize(int col, int row)
}
/* ensure that both src and dst are not NULL */
if (i > 0) {
- memmove(term.line, term.line + i, row * sizeof(Line));
- memmove(term.alt, term.alt + i, row * sizeof(Line));
+ memmove(term.line, term.line + i, row * sizeof(Letter*));
+ memmove(term.alt, term.alt + i, row * sizeof(Letter*));
}
for (i += row; i < term.row; i++) {
free(term.line[i]);
@@ -2423,8 +2307,8 @@ tresize(int col, int row)
}
/* resize to new height */
- term.line = xrealloc(term.line, row * sizeof(Line));
- term.alt = xrealloc(term.alt, row * sizeof(Line));
+ term.line = xrealloc(term.line, row * sizeof(Letter*));
+ term.alt = xrealloc(term.alt, row * sizeof(Letter*));
term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));