]> git.armaanb.net Git - st.git/blob - st.h
Pull term references out of xdrawcursor
[st.git] / st.h
1 /* See LICENSE for license details. */
2
3 /* Arbitrary sizes */
4 #define UTF_SIZ       4
5
6 /* macros */
7 #define MIN(a, b)               ((a) < (b) ? (a) : (b))
8 #define MAX(a, b)               ((a) < (b) ? (b) : (a))
9 #define LEN(a)                  (sizeof(a) / sizeof(a)[0])
10 #define BETWEEN(x, a, b)        ((a) <= (x) && (x) <= (b))
11 #define DIVCEIL(n, d)           (((n) + ((d) - 1)) / (d))
12 #define DEFAULT(a, b)           (a) = (a) ? (a) : (b)
13 #define LIMIT(x, a, b)          (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
14 #define ATTRCMP(a, b)           ((a).mode != (b).mode || (a).fg != (b).fg || \
15                                 (a).bg != (b).bg)
16 #define TIMEDIFF(t1, t2)        ((t1.tv_sec-t2.tv_sec)*1000 + \
17                                 (t1.tv_nsec-t2.tv_nsec)/1E6)
18 #define MODBIT(x, set, bit)     ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
19
20 #define TRUECOLOR(r,g,b)        (1 << 24 | (r) << 16 | (g) << 8 | (b))
21 #define IS_TRUECOL(x)           (1 << 24 & (x))
22
23 enum glyph_attribute {
24         ATTR_NULL       = 0,
25         ATTR_BOLD       = 1 << 0,
26         ATTR_FAINT      = 1 << 1,
27         ATTR_ITALIC     = 1 << 2,
28         ATTR_UNDERLINE  = 1 << 3,
29         ATTR_BLINK      = 1 << 4,
30         ATTR_REVERSE    = 1 << 5,
31         ATTR_INVISIBLE  = 1 << 6,
32         ATTR_STRUCK     = 1 << 7,
33         ATTR_WRAP       = 1 << 8,
34         ATTR_WIDE       = 1 << 9,
35         ATTR_WDUMMY     = 1 << 10,
36         ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
37 };
38
39 enum selection_mode {
40         SEL_IDLE = 0,
41         SEL_EMPTY = 1,
42         SEL_READY = 2
43 };
44
45 enum selection_type {
46         SEL_REGULAR = 1,
47         SEL_RECTANGULAR = 2
48 };
49
50 enum selection_snap {
51         SNAP_WORD = 1,
52         SNAP_LINE = 2
53 };
54
55 typedef unsigned char uchar;
56 typedef unsigned int uint;
57 typedef unsigned long ulong;
58 typedef unsigned short ushort;
59
60 typedef uint_least32_t Rune;
61
62 #define Glyph Glyph_
63 typedef struct {
64         Rune u;           /* character code */
65         ushort mode;      /* attribute flags */
66         uint32_t fg;      /* foreground  */
67         uint32_t bg;      /* background  */
68 } Glyph;
69
70 typedef Glyph *Line;
71
72 typedef struct {
73         Glyph attr; /* current char attributes */
74         int x;
75         int y;
76         char state;
77 } TCursor;
78
79 /* Internal representation of the screen */
80 typedef struct {
81         int row;      /* nb row */
82         int col;      /* nb col */
83         Line *line;   /* screen */
84         Line *alt;    /* alternate screen */
85         int *dirty;   /* dirtyness of lines */
86         TCursor c;    /* cursor */
87         int ocx;      /* old cursor col */
88         int ocy;      /* old cursor row */
89         int top;      /* top    scroll limit */
90         int bot;      /* bottom scroll limit */
91         int mode;     /* terminal mode flags */
92         int esc;      /* escape state flags */
93         char trantbl[4]; /* charset table translation */
94         int charset;  /* current charset */
95         int icharset; /* selected charset for sequence */
96         int *tabs;
97 } Term;
98
99 /* Purely graphic info */
100 typedef struct {
101         int tw, th; /* tty width and height */
102         int w, h; /* window width and height */
103         int ch; /* char height */
104         int cw; /* char width  */
105         int mode; /* window state/mode flags */
106         int cursor; /* cursor style */
107 } TermWindow;
108
109 typedef struct {
110         int mode;
111         int type;
112         int snap;
113         /*
114          * Selection variables:
115          * nb – normalized coordinates of the beginning of the selection
116          * ne – normalized coordinates of the end of the selection
117          * ob – original coordinates of the beginning of the selection
118          * oe – original coordinates of the end of the selection
119          */
120         struct {
121                 int x, y;
122         } nb, ne, ob, oe;
123
124         int alt;
125 } Selection;
126
127 typedef union {
128         int i;
129         uint ui;
130         float f;
131         const void *v;
132 } Arg;
133
134 void die(const char *, ...);
135 void redraw(void);
136 void draw(void);
137
138 void iso14755(const Arg *);
139 void printscreen(const Arg *);
140 void printsel(const Arg *);
141 void sendbreak(const Arg *);
142 void toggleprinter(const Arg *);
143
144 int tattrset(int);
145 void tnew(int, int);
146 void tresize(int, int);
147 void tsetdirtattr(int);
148 void ttynew(char *, char *, char **);
149 size_t ttyread(void);
150 void ttyresize(int, int);
151 void ttywrite(const char *, size_t, int);
152
153 void resettitle(void);
154
155 void selclear(void);
156 void selinit(void);
157 void selstart(int, int, int);
158 void selextend(int, int, int, int);
159 void selnormalize(void);
160 int selected(int, int);
161 char *getsel(void);
162
163 size_t utf8decode(const char *, Rune *, size_t);
164 size_t utf8encode(Rune, char *);
165
166 void *xmalloc(size_t);
167 void *xrealloc(void *, size_t);
168 char *xstrdup(char *);
169
170 /* Globals */
171 extern Term term;
172 extern int cmdfd;
173 extern pid_t pid;
174 extern int oldbutton;
175
176 /* config.h globals */
177 extern char *shell;
178 extern char *utmp;
179 extern char *stty_args;
180 extern char *vtiden;
181 extern char *worddelimiters;
182 extern int allowaltscreen;
183 extern char *termname;
184 extern unsigned int tabspaces;
185 extern unsigned int defaultfg;
186 extern unsigned int defaultbg;