st.h (3498B)
1 /* See LICENSE for license details. */ 2 3 #include <stdint.h> 4 #include <sys/types.h> 5 6 #include <gd.h> 7 8 /* macros */ 9 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 10 #define MAX(a, b) ((a) < (b) ? (b) : (a)) 11 #define LEN(a) (sizeof(a) / sizeof(a)[0]) 12 #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) 13 #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) 14 #define DEFAULT(a, b) (a) = (a) ? (a) : (b) 15 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) 16 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ 17 (a).bg != (b).bg) 18 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ 19 (t1.tv_nsec-t2.tv_nsec)/1E6) 20 #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) 21 22 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) 23 #define IS_TRUECOL(x) (1 << 24 & (x)) 24 #define HISTSIZE 2000 25 26 enum glyph_attribute { 27 ATTR_NULL = 0, 28 ATTR_BOLD = 1 << 0, 29 ATTR_FAINT = 1 << 1, 30 ATTR_ITALIC = 1 << 2, 31 ATTR_UNDERLINE = 1 << 3, 32 ATTR_BLINK = 1 << 4, 33 ATTR_REVERSE = 1 << 5, 34 ATTR_INVISIBLE = 1 << 6, 35 ATTR_STRUCK = 1 << 7, 36 ATTR_WRAP = 1 << 8, 37 ATTR_WIDE = 1 << 9, 38 ATTR_WDUMMY = 1 << 10, 39 ATTR_BOXDRAW = 1 << 11, 40 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, 41 }; 42 43 enum drawing_mode { 44 DRAW_NONE = 0, 45 DRAW_BG = 1 << 0, 46 DRAW_FG = 1 << 1, 47 }; 48 49 enum selection_mode { 50 SEL_IDLE = 0, 51 SEL_EMPTY = 1, 52 SEL_READY = 2 53 }; 54 55 enum selection_type { 56 SEL_REGULAR = 1, 57 SEL_RECTANGULAR = 2 58 }; 59 60 enum selection_snap { 61 SNAP_WORD = 1, 62 SNAP_LINE = 2 63 }; 64 65 typedef unsigned char uchar; 66 typedef unsigned int uint; 67 typedef unsigned long ulong; 68 typedef unsigned short ushort; 69 70 typedef uint_least32_t Rune; 71 72 #define Glyph Glyph_ 73 typedef struct { 74 Rune u; /* character code */ 75 ushort mode; /* attribute flags */ 76 uint32_t fg; /* foreground */ 77 uint32_t bg; /* background */ 78 } Glyph; 79 80 typedef Glyph *Line; 81 82 typedef union { 83 int i; 84 uint ui; 85 float f; 86 const void *v; 87 const char *s; 88 } Arg; 89 90 void die(const char *, ...); 91 void redraw(void); 92 void draw(void); 93 94 void newterm(const Arg *); 95 void printscreen(const Arg *); 96 void printsel(const Arg *); 97 void sendbreak(const Arg *); 98 void toggleprinter(const Arg *); 99 100 int tattrset(int); 101 int tisaltscr(void); 102 void tnew(int, int); 103 void tresize(int, int); 104 void tsetdirtattr(int); 105 void ttyhangup(void); 106 int ttynew(const char *, char *, const char *, char **); 107 size_t ttyread(void); 108 void ttyresize(int, int); 109 void ttywrite(const char *, size_t, int); 110 111 void resettitle(void); 112 113 void selclear(void); 114 void selinit(void); 115 void selstart(int, int, int); 116 void selextend(int, int, int, int); 117 int selected(int, int); 118 char *getsel(void); 119 120 size_t utf8encode(Rune, char *); 121 122 void *xmalloc(size_t); 123 void *xrealloc(void *, size_t); 124 char *xstrdup(const char *); 125 126 int isboxdraw(Rune); 127 ushort boxdrawindex(const Glyph *); 128 #ifdef XFT_VERSION 129 /* only exposed to x.c, otherwise we'll need Xft.h for the types */ 130 void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *); 131 void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int); 132 #endif 133 134 /* config.h globals */ 135 extern char *utmp; 136 extern char *scroll; 137 extern char *stty_args; 138 extern char *vtiden; 139 extern wchar_t *worddelimiters; 140 extern int allowaltscreen; 141 extern int allowwindowops; 142 extern char *termname; 143 extern unsigned int tabspaces; 144 extern unsigned int defaultfg; 145 extern unsigned int defaultbg; 146 extern unsigned int defaultcs; 147 extern const int boxdraw, boxdraw_bold, boxdraw_braille;