st.h 3.5 KB

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