st.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* See LICENSE for license details. */
  2. #include <stdint.h>
  3. #include <sys/types.h>
  4. /* Arbitrary size */
  5. #define HISTSIZE 2000
  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 != (b).mode || (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. #define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - term.scr \
  22. + HISTSIZE + 1) % HISTSIZE] : term.line[(y) - term.scr])
  23. enum glyph_attribute {
  24. ATTR_NULL = 0,
  25. ATTR_BOLD = 1 << 0,
  26. ATTR_FAINT = 1 << 1,
  27. ATTR_ITALIC = 1 << 2,
  28. ATTR_UNDERLINE = 1 << 3,
  29. ATTR_BLINK = 1 << 4,
  30. ATTR_REVERSE = 1 << 5,
  31. ATTR_INVISIBLE = 1 << 6,
  32. ATTR_STRUCK = 1 << 7,
  33. ATTR_WRAP = 1 << 8,
  34. ATTR_WIDE = 1 << 9,
  35. ATTR_WDUMMY = 1 << 10,
  36. ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
  37. };
  38. enum selection_mode {
  39. SEL_IDLE = 0,
  40. SEL_EMPTY = 1,
  41. SEL_READY = 2
  42. };
  43. enum selection_type {
  44. SEL_REGULAR = 1,
  45. SEL_RECTANGULAR = 2
  46. };
  47. enum selection_snap {
  48. SNAP_WORD = 1,
  49. SNAP_LINE = 2
  50. };
  51. typedef unsigned char uchar;
  52. typedef unsigned int uint;
  53. typedef unsigned long ulong;
  54. typedef unsigned short ushort;
  55. typedef uint_least32_t Rune;
  56. #define Glyph Glyph_
  57. typedef struct {
  58. Rune u; /* character code */
  59. ushort mode; /* attribute flags */
  60. uint32_t fg; /* foreground */
  61. uint32_t bg; /* background */
  62. } Glyph;
  63. typedef Glyph *Line;
  64. typedef union {
  65. int i;
  66. uint ui;
  67. float f;
  68. const void *v;
  69. } Arg;
  70. typedef struct {
  71. uint b;
  72. uint mask;
  73. void (*func)(const Arg *);
  74. const Arg arg;
  75. } MouseKey;
  76. void die(const char *, ...);
  77. void redraw(void);
  78. void draw(void);
  79. void externalpipe(const Arg *);
  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. int tattrset(int);
  86. void tnew(int, int);
  87. void tresize(int, int);
  88. void tsetdirtattr(int);
  89. void ttyhangup(void);
  90. int ttynew(char *, char *, char *, char **);
  91. size_t ttyread(void);
  92. void ttyresize(int, int);
  93. void ttywrite(const char *, size_t, int);
  94. void resettitle(void);
  95. void selclear(void);
  96. void selinit(void);
  97. void selstart(int, int, int);
  98. void selextend(int, int, int, int);
  99. int selected(int, int);
  100. char *getsel(void);
  101. size_t utf8encode(Rune, char *);
  102. void *xmalloc(size_t);
  103. void *xrealloc(void *, size_t);
  104. char *xstrdup(char *);
  105. void kscrolldown(const Arg *);
  106. void kscrollup(const Arg *);
  107. /* config.h globals */
  108. extern char *utmp;
  109. extern char *stty_args;
  110. extern char *vtiden;
  111. extern char *worddelimiters;
  112. extern int allowaltscreen;
  113. extern char *termname;
  114. extern unsigned int tabspaces;
  115. extern unsigned int alpha;
  116. extern unsigned int defaultfg;
  117. extern unsigned int defaultbg;
  118. extern MouseKey mkeys[];