Xinqi Bao's Git
1 /* See LICENSE for licence details. */
12 #include <sys/ioctl.h>
13 #include <sys/select.h>
15 #include <sys/types.h>
19 #include <X11/keysym.h>
20 #include <X11/Xutil.h>
23 #define KEYDELETE "\033[3~"
24 #define KEYHOME "\033[1~"
25 #define KEYEND "\033[4~"
26 #define KEYPREV "\033[5~"
27 #define KEYNEXT "\033[6~"
30 #define SHELL "/bin/bash"
35 #define LINESPACE 1 /* additional pixel between each line */
41 #define BellCol DefaultFG /* visual bell color */
43 static char* colorname
[] = {
58 #define SERRNO strerror(errno)
59 #define MIN(a, b) ((a) < (b) ? (a) : (b))
60 #define MAX(a, b) ((a) < (b) ? (b) : (a))
61 #define LEN(a) (sizeof(a) / sizeof(a[0]))
62 #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
63 #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
64 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
67 enum { ATnone
=0 , ATreverse
=1 , ATunderline
=2, ATbold
=4 }; /* Attribute */
68 enum { CSup
, CSdown
, CSright
, CSleft
, CShide
, CSdraw
, CSwrap
, CSsave
, CSload
}; /* Cursor */
69 enum { CRset
=1 , CRupdate
=2 }; /* Character state */
70 enum { TMwrap
=1 , TMinsert
=2, TMaltcharset
}; /* Terminal mode */
71 enum { SCupdate
, SCredraw
}; /* screen draw mode */
76 char c
; /* character code */
77 char mode
; /* attribute flags */
78 Color fg
; /* foreground */
79 Color bg
; /* background */
80 char state
; /* state flag */
86 Glyph attr
; /* current char attributes */
92 /* Escape sequence structs */
94 char buf
[ESCSIZ
+1]; /* raw string */
95 int len
; /* raw string length */
96 /* ESC <pre> [[ [<priv>] <arg> [;]] <mode>] */
100 int narg
; /* nb of args */
104 /* Internal representation of the screen */
106 int row
; /* nb row */
107 int col
; /* nb col */
108 Line
* line
; /* screen */
109 TCursor c
; /* cursor */
110 int top
; /* top scroll limit */
111 int bot
; /* bottom scroll limit */
112 int mode
; /* terminal mode */
115 /* Purely graphic info */
120 int w
; /* window width */
121 int h
; /* window height */
122 int ch
; /* char height */
123 int cw
; /* char width */
126 /* Drawing Context */
128 unsigned long col
[LEN(colorname
)];
134 void die(const char *errstr
, ...);
138 void kpress(XKeyEvent
*);
139 void resize(XEvent
*);
145 void eschandle(void);
149 void tclearregion(int, int, int, int);
152 void tdeletechar(int);
153 void tdeleteline(int);
155 void tinsertblank(int);
156 void tinsertblankline(int);
157 void tmoveto(int, int);
161 void tputs(char*, int);
162 void tresize(int, int);
164 void tsetattr(int*, int);
166 void tsetscroll(int, int);
170 void ttyresize(int, int);
171 void ttywrite(char *, size_t);
173 unsigned long xgetcol(const char *);
174 void xclear(int, int, int, int);
176 void xdrawc(int, int, Glyph
);