From b3ea2b804fbd35babac86c83c718a5491542db7c Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 6 Jun 2020 13:26:49 -0700 Subject: done tinkering with st --- sys/cmd/term/term.h | 249 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 188 insertions(+), 61 deletions(-) (limited to 'sys/cmd/term/term.h') diff --git a/sys/cmd/term/term.h b/sys/cmd/term/term.h index 62c407f..a155bbe 100644 --- a/sys/cmd/term/term.h +++ b/sys/cmd/term/term.h @@ -18,16 +18,19 @@ #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 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) +#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) #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) - #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) #define IS_TRUECOL(x) (1 << 24 & (x)) -#define iota(x) 1 << (x) +#define iota(x) 1 << (x) + +/* arbitrary sizes */ +#define ESC_BUF_SIZ (128*UTFmax) +#define ESC_ARG_SIZ 16 +#define STR_BUF_SIZ ESC_BUF_SIZ +#define STR_ARG_SIZ ESC_ARG_SIZ // ----------------------------------------------------------------------- // constants @@ -64,32 +67,88 @@ enum { SnapLine = 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, +/* 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, +}; + +/* 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), +}; + +/* window mode */ +enum { + Wvisible = iota(0), + Wfocused = iota(1), + Wappkeypad = iota(2), + Wmousebtn = iota(3), + Wmousemotion = iota(4), + Wreverse = iota(5), + Wkbdblock = iota(6), + Whide = iota(7), + Wappcursor = iota(8), + Wmousesgr = iota(9), + W8bit = iota(10), + Wblink = iota(11), + Wbflink = iota(12), + Wfocus = iota(13), + Wmousex10 = iota(14), + Wmousemany = iota(15), + Wbrcktpaste = iota(16), + Wnumlock = iota(17), Wmouse = Wmousebtn|Wmousemotion|Wmousex10|Wmousemany, }; // ----------------------------------------------------------------------- // types -typedef struct Letter Letter; + +/* term.c */ +typedef struct Letter Letter; +typedef struct Dot Dot; +typedef struct Selection Selection; +typedef struct Terminal Terminal; + +typedef union Arg Arg; struct Letter { rune u; /* character code */ @@ -98,20 +157,88 @@ struct Letter { uint32_t bg; /* background */ }; -typedef Letter *Line; - -typedef union { - int i; - uint ui; +union Arg { + int i; + uint ui; float f; - void *v; - char *s; -} Arg; + void *v; + char *s; +}; + +struct Dot { + Letter attr; /* current char attributes */ + int x; + int y; + char state; +}; + +struct Selection { + 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; +}; + +/* Internal representation of the screen */ +struct Terminal { + int row; /* nb row */ + int col; /* nb col */ + Letter **line; /* screen */ + Letter **alt; /* alternate screen */ + int *dirty; /* dirtyness of lines */ + Dot 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 */ +}; + +/* CSI Escape sequence structs */ +/* ESC '[' [[ [] [;]] []] */ +typedef struct { + char buf[ESC_BUF_SIZ]; /* raw string */ + ulong 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 [[ [] [;]] ] 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; + + void xbell(void); void xclipcopy(void); void xdrawcursor(int, int, Letter, int, int, Letter); -void xdrawline(Line, int, int, int); +void xdrawline(Letter*, int, int, int); void xfinishdraw(void); void xloadcols(void); int xsetcolorname(int, char *); @@ -127,20 +254,20 @@ void die( char *, ...); void redraw(void); void draw(void); -void printscreen(Arg *); -void printsel(Arg *); -void sendbreak(Arg *); -void toggleprinter(Arg *); - -int tattrset(int); -void tnew(int, int); -void tresize(int, int); -void tsetdirtattr(int); -void ttyhangup(void); -int ttynew(char *, char *, char *, char **); -size_t ttyread(void); -void ttyresize(int, int); -void ttywrite( char *, size_t, int); +void printscreen(Arg *); +void printsel(Arg *); +void sendbreak(Arg *); +void toggleprinter(Arg *); + +int tattrset(int); +void tnew(int, int); +void tresize(int, int); +void tsetdirtattr(int); +void ttyhangup(void); +int ttynew(char *, char *, char *, char **); +ulong ttyread(void); +void ttyresize(int, int); +void ttywrite( char *, size_t, int); void resettitle(void); @@ -148,7 +275,7 @@ void selclear(void); void selinit(void); void selstart(int, int, int); void selextend(int, int, int, int); -int selected(int, int); +int selected(int, int); char *getsel(void); void *xmalloc(size_t); @@ -156,14 +283,14 @@ void *xrealloc(void *, size_t); char *xstrdup(char *); /* config.h globals */ -extern char *utmp; -extern char *scroll; -extern char *stty_args; -extern char *vtiden; -extern wchar_t *worddelimiters; -extern int allowaltscreen; -extern int allowwindowops; -extern char *termname; -extern unsigned int tabspaces; -extern unsigned int defaultfg; -extern unsigned int defaultbg; +extern char *utmp; +extern char *scroll; +extern char *stty_args; +extern char *vtiden; +extern wchar *worddelimiters; +extern int allowaltscreen; +extern int allowwindowops; +extern char *termname; +extern uint tabspaces; +extern uint defaultfg; +extern uint defaultbg; -- cgit v1.2.1