st.h 2.9 KB

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