aboutsummaryrefslogtreecommitdiff
path: root/st.h
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2009-05-10 13:17:09 +0100
committerAnselm R Garbe <garbeam@gmail.com>2009-05-10 13:17:09 +0100
commitd58dd3b8bc42ed31232e4145696d7dacb117a31c (patch)
treedfe3362a600e9491a687cd765158b70d3328333d /st.h
parent802f1922f93aef1e4876719e107828a1fa15b1a6 (diff)
downloadst-patched-d58dd3b8bc42ed31232e4145696d7dacb117a31c.tar.bz2
st-patched-d58dd3b8bc42ed31232e4145696d7dacb117a31c.tar.xz
st-patched-d58dd3b8bc42ed31232e4145696d7dacb117a31c.zip
backport of local changes
Diffstat (limited to 'st.h')
-rw-r--r--st.h181
1 files changed, 181 insertions, 0 deletions
diff --git a/st.h b/st.h
new file mode 100644
index 0000000..be39ef4
--- /dev/null
+++ b/st.h
@@ -0,0 +1,181 @@
1/* See LICENSE for licence details. */
2
3#define _XOPEN_SOURCE
4#include <ctype.h>
5#include <fcntl.h>
6#include <locale.h>
7#include <stdarg.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14#include <sys/select.h>
15#include <sys/ioctl.h>
16#include <X11/Xlib.h>
17#include <X11/keysym.h>
18#include <X11/Xutil.h>
19
20/* special keys */
21#define KEYDELETE "\033[3~"
22#define KEYHOME "\033[1~"
23#define KEYEND "\033[4~"
24#define KEYPREV "\033[5~"
25#define KEYNEXT "\033[6~"
26
27#define TNAME "st"
28#define SHELL "/bin/bash"
29#define TAB 8
30
31#define FONT "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"
32#define BORDER 3
33#define LINESPACE 1 /* additional pixel between each line */
34
35/* Default colors */
36#define DefaultFG 7
37#define DefaultBG 0
38#define DefaultCS 1
39#define BellCol DefaultFG /* visual bell color */
40
41static char* colorname[] = {
42 "black",
43 "red",
44 "green",
45 "yellow",
46 "blue",
47 "magenta",
48 "cyan",
49 "white",
50};
51
52
53/* Arbitrary sizes */
54#define ESCSIZ 256
55#define ESCARG 16
56
57#define MIN(a, b) ((a) < (b) ? (a) : (b))
58#define MAX(a, b) ((a) < (b) ? (b) : (a))
59#define LEN(a) (sizeof(a) / sizeof(a[0]))
60#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
61#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
62#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
63
64
65enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 }; /* Attribute */
66enum { CSup, CSdown, CSright, CSleft, CShide, CSdraw, CSwrap, CSsave, CSload }; /* Cursor */
67enum { CRset=1 , CRupdate=2 }; /* Character state */
68enum { TMwrap=1 , TMinsert=2 }; /* Terminal mode */
69enum { SCupdate, SCredraw }; /* screen draw mode */
70
71#ifdef TRUECOLOR
72#error Truecolor not implemented yet
73typedef int Color;
74#else
75typedef char Color;
76#endif
77
78
79typedef struct {
80 char c; /* character code */
81 char mode; /* attribute flags */
82 Color fg; /* foreground */
83 Color bg; /* background */
84 char state; /* state flag */
85} Glyph;
86
87typedef Glyph* Line;
88
89typedef struct {
90 Glyph attr; /* current char attributes */
91 char hidden;
92 int x;
93 int y;
94} TCursor;
95
96/* Escape sequence structs */
97typedef struct {
98 char buf[ESCSIZ+1]; /* raw string */
99 int len; /* raw string length */
100 /* ESC <pre> [[ [<priv>] <arg> [;]] <mode>] */
101 char pre;
102 char priv;
103 int arg[ESCARG+1];
104 int narg; /* nb of args */
105 char mode;
106} Escseq;
107
108/* Internal representation of the screen */
109typedef struct {
110 int row; /* nb row */
111 int col; /* nb col */
112 Line* line; /* screen */
113 TCursor c; /* cursor */
114 int top; /* top scroll limit */
115 int bot; /* bottom scroll limit */
116 int mode; /* terminal mode */
117} Term;
118
119/* Purely graphic info */
120typedef struct {
121 Display* dis;
122 Window win;
123 int scr;
124 int w; /* window width */
125 int h; /* window height */
126 int ch; /* char height */
127 int cw; /* char width */
128} XWindow;
129
130/* Drawing Context */
131typedef struct {
132 unsigned long col[LEN(colorname)];
133 XFontStruct* font;
134 GC gc;
135} DC;
136
137
138void die(const char *errstr, ...);
139void draw(int);
140void execsh(void);
141void kpress(XKeyEvent *);
142void resize(XEvent *);
143void run(void);
144
145int escaddc(char);
146int escfinal(char);
147void escdump(void);
148void eschandle(void);
149void escparse(void);
150void escreset(void);
151
152void tclearregion(int, int, int, int);
153void tcpos(int);
154void tcursor(int);
155void tdeletechar(int);
156void tdeleteline(int);
157void tdump(void);
158void tinsertblank(int);
159void tinsertblankline(int);
160void tmoveto(int, int);
161void tnew(int, int);
162void tnewline(void);
163void tputc(char);
164void tputs(char*, int);
165void tresize(int, int);
166void tscroll(void);
167void tsetattr(int*, int);
168void tsetchar(char);
169void tsetscroll(int, int);
170
171void ttynew(void);
172void ttyread(void);
173void ttyresize(int, int);
174void ttywrite(char *, size_t);
175
176unsigned long xgetcol(const char *);
177void xclear(int, int, int, int);
178void xcursor(int);
179void xdrawc(int, int, Glyph);
180void xinit(void);
181void xscroll(void);