Simple Terminal from SuckLess
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.

120 lines
2.7 KiB

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