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