]> git.armaanb.net Git - st.git/blob - st.h
Switch to zenburn theme
[st.git] / st.h
1 /* See LICENSE for license details. */
2
3 #include <stdint.h>
4 #include <sys/types.h>
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 & (~ATTR_WRAP) & (~ATTR_LIGA)) != ((b).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) || \
15                                 (a).fg != (b).fg || \
16                                 (a).bg != (b).bg)
17 #define TIMEDIFF(t1, t2)        ((t1.tv_sec-t2.tv_sec)*1000 + \
18                                 (t1.tv_nsec-t2.tv_nsec)/1E6)
19 #define MODBIT(x, set, bit)     ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
20
21 #define TRUECOLOR(r,g,b)        (1 << 24 | (r) << 16 | (g) << 8 | (b))
22 #define IS_TRUECOL(x)           (1 << 24 & (x))
23
24 enum glyph_attribute {
25         ATTR_NULL       = 0,
26         ATTR_BOLD       = 1 << 0,
27         ATTR_FAINT      = 1 << 1,
28         ATTR_ITALIC     = 1 << 2,
29         ATTR_UNDERLINE  = 1 << 3,
30         ATTR_BLINK      = 1 << 4,
31         ATTR_REVERSE    = 1 << 5,
32         ATTR_INVISIBLE  = 1 << 6,
33         ATTR_STRUCK     = 1 << 7,
34         ATTR_WRAP       = 1 << 8,
35         ATTR_WIDE       = 1 << 9,
36         ATTR_WDUMMY     = 1 << 10,
37         ATTR_LIGA       = 1 << 11,
38         ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
39 };
40
41 enum selection_mode {
42         SEL_IDLE = 0,
43         SEL_EMPTY = 1,
44         SEL_READY = 2
45 };
46
47 enum selection_type {
48         SEL_REGULAR = 1,
49         SEL_RECTANGULAR = 2
50 };
51
52 enum selection_snap {
53         SNAP_WORD = 1,
54         SNAP_LINE = 2
55 };
56
57 typedef unsigned char uchar;
58 typedef unsigned int uint;
59 typedef unsigned long ulong;
60 typedef unsigned short ushort;
61
62 typedef uint_least32_t Rune;
63
64 #define Glyph Glyph_
65 typedef struct {
66         Rune u;           /* character code */
67         ushort mode;      /* attribute flags */
68         uint32_t fg;      /* foreground  */
69         uint32_t bg;      /* background  */
70 } Glyph;
71
72 typedef Glyph *Line;
73
74 typedef union {
75         int i;
76         uint ui;
77         float f;
78         const void *v;
79         const char *s;
80 } Arg;
81
82 void die(const char *, ...);
83 void redraw(void);
84 void draw(void);
85
86 void printscreen(const Arg *);
87 void printsel(const Arg *);
88 void sendbreak(const Arg *);
89 void toggleprinter(const Arg *);
90 void copyurl(const Arg *);
91
92 int tattrset(int);
93 void tnew(int, int);
94 void tresize(int, int);
95 void tsetdirtattr(int);
96 void ttyhangup(void);
97 int ttynew(const char *, char *, const char *, char **);
98 size_t ttyread(void);
99 void ttyresize(int, int);
100 void ttywrite(const char *, size_t, int);
101
102 void resettitle(void);
103
104 void selclear(void);
105 void selinit(void);
106 void selstart(int, int, int);
107 void selextend(int, int, int, int);
108 int selected(int, int);
109 char *getsel(void);
110
111 size_t utf8encode(Rune, char *);
112
113 void *xmalloc(size_t);
114 void *xrealloc(void *, size_t);
115 char *xstrdup(const char *);
116
117 /* config.h globals */
118 extern char *utmp;
119 extern char *scroll;
120 extern char *stty_args;
121 extern char *vtiden;
122 extern wchar_t *worddelimiters;
123 extern int allowaltscreen;
124 extern int allowwindowops;
125 extern char *termname;
126 extern unsigned int tabspaces;
127 extern unsigned int defaultfg;
128 extern unsigned int defaultbg;