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.

186 lines
4.3 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 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 struct {
  61. Glyph attr; /* current char attributes */
  62. int x;
  63. int y;
  64. char state;
  65. } TCursor;
  66. /* Internal representation of the screen */
  67. typedef struct {
  68. int row; /* nb row */
  69. int col; /* nb col */
  70. Line *line; /* screen */
  71. Line *alt; /* alternate screen */
  72. int *dirty; /* dirtyness of lines */
  73. TCursor c; /* cursor */
  74. int ocx; /* old cursor col */
  75. int ocy; /* old cursor row */
  76. int top; /* top scroll limit */
  77. int bot; /* bottom scroll limit */
  78. int mode; /* terminal mode flags */
  79. int esc; /* escape state flags */
  80. char trantbl[4]; /* charset table translation */
  81. int charset; /* current charset */
  82. int icharset; /* selected charset for sequence */
  83. int *tabs;
  84. } Term;
  85. /* Purely graphic info */
  86. typedef struct {
  87. int tw, th; /* tty width and height */
  88. int w, h; /* window width and height */
  89. int ch; /* char height */
  90. int cw; /* char width */
  91. int mode; /* window state/mode flags */
  92. int cursor; /* cursor style */
  93. } TermWindow;
  94. typedef struct {
  95. int mode;
  96. int type;
  97. int snap;
  98. /*
  99. * Selection variables:
  100. * nb normalized coordinates of the beginning of the selection
  101. * ne normalized coordinates of the end of the selection
  102. * ob original coordinates of the beginning of the selection
  103. * oe original coordinates of the end of the selection
  104. */
  105. struct {
  106. int x, y;
  107. } nb, ne, ob, oe;
  108. int alt;
  109. } Selection;
  110. typedef union {
  111. int i;
  112. uint ui;
  113. float f;
  114. const void *v;
  115. } Arg;
  116. void die(const char *, ...);
  117. void redraw(void);
  118. void draw(void);
  119. void iso14755(const Arg *);
  120. void printscreen(const Arg *);
  121. void printsel(const Arg *);
  122. void sendbreak(const Arg *);
  123. void toggleprinter(const Arg *);
  124. int tattrset(int);
  125. void tnew(int, int);
  126. void tresize(int, int);
  127. void tsetdirtattr(int);
  128. void ttynew(char *, char *, char **);
  129. size_t ttyread(void);
  130. void ttyresize(int, int);
  131. void ttywrite(const char *, size_t, int);
  132. void resettitle(void);
  133. void selclear(void);
  134. void selinit(void);
  135. void selstart(int, int, int);
  136. void selextend(int, int, int, int);
  137. void selnormalize(void);
  138. int selected(int, int);
  139. char *getsel(void);
  140. size_t utf8decode(const char *, Rune *, size_t);
  141. size_t utf8encode(Rune, char *);
  142. void *xmalloc(size_t);
  143. void *xrealloc(void *, size_t);
  144. char *xstrdup(char *);
  145. /* Globals */
  146. extern Term term;
  147. extern int cmdfd;
  148. extern pid_t pid;
  149. extern int oldbutton;
  150. /* config.h globals */
  151. extern char *shell;
  152. extern char *utmp;
  153. extern char *stty_args;
  154. extern char *vtiden;
  155. extern char *worddelimiters;
  156. extern int allowaltscreen;
  157. extern char *termname;
  158. extern unsigned int tabspaces;
  159. extern unsigned int defaultfg;
  160. extern unsigned int defaultbg;