st.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. void die(const char *, ...);
  71. void redraw(void);
  72. void draw(void);
  73. void printscreen(const Arg *);
  74. void printsel(const Arg *);
  75. void sendbreak(const Arg *);
  76. void toggleprinter(const Arg *);
  77. int tattrset(int);
  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. void kscrolldown(const Arg *);
  98. void kscrollup(const Arg *);
  99. /* config.h globals */
  100. extern char *utmp;
  101. extern char *stty_args;
  102. extern char *vtiden;
  103. extern wchar_t *worddelimiters;
  104. extern int allowaltscreen;
  105. extern char *termname;
  106. extern unsigned int tabspaces;
  107. extern unsigned int alpha;
  108. extern unsigned int defaultfg;
  109. extern unsigned int defaultbg;