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