1 /* See LICENSE for license details. */
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 || \
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)))
20 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
21 #define IS_TRUECOL(x) (1 << 24 & (x))
23 enum glyph_attribute {
28 ATTR_UNDERLINE = 1 << 3,
30 ATTR_REVERSE = 1 << 5,
31 ATTR_INVISIBLE = 1 << 6,
35 ATTR_WDUMMY = 1 << 10,
36 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
55 typedef unsigned char uchar;
56 typedef unsigned int uint;
57 typedef unsigned long ulong;
58 typedef unsigned short ushort;
60 typedef uint_least32_t Rune;
64 Rune u; /* character code */
65 ushort mode; /* attribute flags */
66 uint32_t fg; /* foreground */
67 uint32_t bg; /* background */
73 Glyph attr; /* current char attributes */
79 /* Internal representation of the screen */
83 Line *line; /* screen */
84 Line *alt; /* alternate screen */
85 int *dirty; /* dirtyness of lines */
86 TCursor c; /* cursor */
87 int top; /* top scroll limit */
88 int bot; /* bottom scroll limit */
89 int mode; /* terminal mode flags */
90 int esc; /* escape state flags */
91 char trantbl[4]; /* charset table translation */
92 int charset; /* current charset */
93 int icharset; /* selected charset for sequence */
97 /* Purely graphic info */
99 int tw, th; /* tty width and height */
100 int w, h; /* window width and height */
101 int ch; /* char height */
102 int cw; /* char width */
103 int mode; /* window state/mode flags */
104 int cursor; /* cursor style */
112 * Selection variables:
113 * nb – normalized coordinates of the beginning of the selection
114 * ne – normalized coordinates of the end of the selection
115 * ob – original coordinates of the beginning of the selection
116 * oe – original coordinates of the end of the selection
132 void die(const char *, ...);
135 void iso14755(const Arg *);
136 void printscreen(const Arg *);
137 void printsel(const Arg *);
138 void sendbreak(const Arg *);
139 void toggleprinter(const Arg *);
143 void tresize(int, int);
144 void tsetdirtattr(int);
145 void ttynew(char *, char *, char **);
146 size_t ttyread(void);
147 void ttyresize(int, int);
148 void ttywrite(const char *, size_t, int);
150 void resettitle(void);
154 void selstart(int, int, int);
155 void selextend(int, int, int, int);
156 void selnormalize(void);
157 int selected(int, int);
160 size_t utf8decode(const char *, Rune *, size_t);
161 size_t utf8encode(Rune, char *);
163 void *xmalloc(size_t);
164 void *xrealloc(void *, size_t);
165 char *xstrdup(char *);
171 extern int oldbutton;
173 /* config.h globals */
176 extern char *stty_args;
178 extern char *worddelimiters;
179 extern int allowaltscreen;
180 extern char *termname;
181 extern unsigned int tabspaces;
182 extern unsigned int defaultfg;
183 extern unsigned int defaultbg;