st

git clone git://mattcarlson.org/repos/st.git
Log | Files | Refs

st.h (3670B)


      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_BOXDRAW    = 1 << 11,
     38     ATTR_LIGA       = 1 << 12,
     39 	ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
     40 	ATTR_DIRTYUNDERLINE = 1 << 15,
     41 };
     42 
     43 enum selection_mode {
     44 	SEL_IDLE = 0,
     45 	SEL_EMPTY = 1,
     46 	SEL_READY = 2
     47 };
     48 
     49 enum selection_type {
     50 	SEL_REGULAR = 1,
     51 	SEL_RECTANGULAR = 2
     52 };
     53 
     54 enum selection_snap {
     55 	SNAP_WORD = 1,
     56 	SNAP_LINE = 2
     57 };
     58 
     59 typedef unsigned char uchar;
     60 typedef unsigned int uint;
     61 typedef unsigned long ulong;
     62 typedef unsigned short ushort;
     63 
     64 typedef uint_least32_t Rune;
     65 
     66 #define Glyph Glyph_
     67 typedef struct {
     68 	Rune u;           /* character code */
     69 	ushort mode;      /* attribute flags */
     70 	uint32_t fg;      /* foreground  */
     71 	uint32_t bg;      /* background  */
     72 	int ustyle;	  /* underline style */
     73 	int ucolor[3];    /* underline color */
     74 } Glyph;
     75 
     76 typedef Glyph *Line;
     77 
     78 typedef union {
     79 	int i;
     80 	uint ui;
     81 	float f;
     82 	const void *v;
     83 	const char *s;
     84 } Arg;
     85 
     86 void die(const char *, ...);
     87 void redraw(void);
     88 void tfulldirt(void);
     89 void draw(void);
     90 
     91 void kscrolldown(const Arg *);
     92 void kscrollup(const Arg *);
     93 void printscreen(const Arg *);
     94 void printsel(const Arg *);
     95 void sendbreak(const Arg *);
     96 void toggleprinter(const Arg *);
     97 
     98 int tattrset(int);
     99 int tisaltscr(void);
    100 void tnew(int, int);
    101 void tresize(int, int);
    102 void tsetdirtattr(int);
    103 void ttyhangup(void);
    104 int ttynew(const char *, char *, const char *, char **);
    105 size_t ttyread(void);
    106 void ttyresize(int, int);
    107 void ttywrite(const char *, size_t, int);
    108 
    109 void resettitle(void);
    110 
    111 void selclear(void);
    112 void selinit(void);
    113 void selstart(int, int, int);
    114 void selextend(int, int, int, int);
    115 int selected(int, int);
    116 char *getsel(void);
    117 
    118 size_t utf8encode(Rune, char *);
    119 
    120 void *xmalloc(size_t);
    121 void *xrealloc(void *, size_t);
    122 char *xstrdup(const char *);
    123 
    124 int isboxdraw(Rune);
    125 ushort boxdrawindex(const Glyph *);
    126 #ifdef XFT_VERSION
    127 /* only exposed to x.c, otherwise we'll need Xft.h for the types */
    128 void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *);
    129 void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int);
    130 #endif
    131 
    132 /* config.h globals */
    133 extern char *utmp;
    134 extern char *scroll;
    135 extern char *stty_args;
    136 extern char *vtiden;
    137 extern wchar_t *worddelimiters;
    138 extern int allowaltscreen;
    139 extern int allowwindowops;
    140 extern char *termname;
    141 extern unsigned int tabspaces;
    142 extern unsigned int defaultfg;
    143 extern unsigned int defaultbg;
    144 extern float alpha, alphaUnfocused;
    145 extern int boxdraw, boxdraw_bold, boxdraw_braille;