My build of suckless st terminal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
5.1 KiB

  1. /* See LICENSE for license details. */
  2. /* Arbitrary sizes */
  3. #define UTF_SIZ 4
  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 IS_SET(flag) ((term.mode & (flag)) != 0)
  15. #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
  16. (t1.tv_nsec-t2.tv_nsec)/1E6)
  17. #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
  18. #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
  19. #define IS_TRUECOL(x) (1 << 24 & (x))
  20. enum glyph_attribute {
  21. ATTR_NULL = 0,
  22. ATTR_BOLD = 1 << 0,
  23. ATTR_FAINT = 1 << 1,
  24. ATTR_ITALIC = 1 << 2,
  25. ATTR_UNDERLINE = 1 << 3,
  26. ATTR_BLINK = 1 << 4,
  27. ATTR_REVERSE = 1 << 5,
  28. ATTR_INVISIBLE = 1 << 6,
  29. ATTR_STRUCK = 1 << 7,
  30. ATTR_WRAP = 1 << 8,
  31. ATTR_WIDE = 1 << 9,
  32. ATTR_WDUMMY = 1 << 10,
  33. ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
  34. };
  35. enum term_mode {
  36. MODE_WRAP = 1 << 0,
  37. MODE_INSERT = 1 << 1,
  38. MODE_APPKEYPAD = 1 << 2,
  39. MODE_ALTSCREEN = 1 << 3,
  40. MODE_CRLF = 1 << 4,
  41. MODE_MOUSEBTN = 1 << 5,
  42. MODE_MOUSEMOTION = 1 << 6,
  43. MODE_REVERSE = 1 << 7,
  44. MODE_KBDLOCK = 1 << 8,
  45. MODE_HIDE = 1 << 9,
  46. MODE_ECHO = 1 << 10,
  47. MODE_APPCURSOR = 1 << 11,
  48. MODE_MOUSESGR = 1 << 12,
  49. MODE_8BIT = 1 << 13,
  50. MODE_BLINK = 1 << 14,
  51. MODE_FBLINK = 1 << 15,
  52. MODE_FOCUS = 1 << 16,
  53. MODE_MOUSEX10 = 1 << 17,
  54. MODE_MOUSEMANY = 1 << 18,
  55. MODE_BRCKTPASTE = 1 << 19,
  56. MODE_PRINT = 1 << 20,
  57. MODE_UTF8 = 1 << 21,
  58. MODE_SIXEL = 1 << 22,
  59. MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
  60. |MODE_MOUSEMANY,
  61. };
  62. enum selection_mode {
  63. SEL_IDLE = 0,
  64. SEL_EMPTY = 1,
  65. SEL_READY = 2
  66. };
  67. enum selection_type {
  68. SEL_REGULAR = 1,
  69. SEL_RECTANGULAR = 2
  70. };
  71. enum selection_snap {
  72. SNAP_WORD = 1,
  73. SNAP_LINE = 2
  74. };
  75. typedef unsigned char uchar;
  76. typedef unsigned int uint;
  77. typedef unsigned long ulong;
  78. typedef unsigned short ushort;
  79. typedef uint_least32_t Rune;
  80. #define Glyph Glyph_
  81. typedef struct {
  82. Rune u; /* character code */
  83. ushort mode; /* attribute flags */
  84. uint32_t fg; /* foreground */
  85. uint32_t bg; /* background */
  86. } Glyph;
  87. typedef Glyph *Line;
  88. typedef struct {
  89. Glyph attr; /* current char attributes */
  90. int x;
  91. int y;
  92. char state;
  93. } TCursor;
  94. /* Internal representation of the screen */
  95. typedef struct {
  96. int row; /* nb row */
  97. int col; /* nb col */
  98. Line *line; /* screen */
  99. Line *alt; /* alternate screen */
  100. int *dirty; /* dirtyness of lines */
  101. TCursor c; /* cursor */
  102. int top; /* top scroll limit */
  103. int bot; /* bottom scroll limit */
  104. int mode; /* terminal mode flags */
  105. int esc; /* escape state flags */
  106. char trantbl[4]; /* charset table translation */
  107. int charset; /* current charset */
  108. int icharset; /* selected charset for sequence */
  109. int numlock; /* lock numbers in keyboard */
  110. int *tabs;
  111. } Term;
  112. /* Purely graphic info */
  113. typedef struct {
  114. int tw, th; /* tty width and height */
  115. int w, h; /* window width and height */
  116. int ch; /* char height */
  117. int cw; /* char width */
  118. char state; /* focus, redraw, visible */
  119. int cursor; /* cursor style */
  120. } TermWindow;
  121. typedef struct {
  122. int mode;
  123. int type;
  124. int snap;
  125. /*
  126. * Selection variables:
  127. * nb normalized coordinates of the beginning of the selection
  128. * ne normalized coordinates of the end of the selection
  129. * ob original coordinates of the beginning of the selection
  130. * oe original coordinates of the end of the selection
  131. */
  132. struct {
  133. int x, y;
  134. } nb, ne, ob, oe;
  135. int alt;
  136. } Selection;
  137. typedef union {
  138. int i;
  139. uint ui;
  140. float f;
  141. const void *v;
  142. } Arg;
  143. void die(const char *, ...);
  144. void redraw(void);
  145. void iso14755(const Arg *);
  146. void numlock(const Arg *);
  147. void printscreen(const Arg *);
  148. void printsel(const Arg *);
  149. void sendbreak(const Arg *);
  150. void toggleprinter(const Arg *);
  151. int tattrset(int);
  152. void tnew(int, int);
  153. void tresize(int, int);
  154. void tsetdirt(int, int);
  155. void tsetdirtattr(int);
  156. void ttynew(char *, char *, char **);
  157. size_t ttyread(void);
  158. void ttyresize(int, int);
  159. void ttysend(char *, size_t);
  160. void ttywrite(const char *, size_t);
  161. void resettitle(void);
  162. void selclear(void);
  163. void selinit(void);
  164. void selnormalize(void);
  165. int selected(int, int);
  166. char *getsel(void);
  167. size_t utf8decode(const char *, Rune *, size_t);
  168. size_t utf8encode(Rune, char *);
  169. void *xmalloc(size_t);
  170. void *xrealloc(void *, size_t);
  171. char *xstrdup(char *);
  172. /* Globals */
  173. extern Term term;
  174. extern Selection sel;
  175. extern int cmdfd;
  176. extern pid_t pid;
  177. extern int oldbutton;
  178. /* config.h globals */
  179. extern char *shell;
  180. extern char *utmp;
  181. extern char *stty_args;
  182. extern char *vtiden;
  183. extern char *worddelimiters;
  184. extern int allowaltscreen;
  185. extern char *termname;
  186. extern unsigned int tabspaces;
  187. extern unsigned int defaultfg;
  188. extern unsigned int defaultbg;