termemu.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #include <_cheader.h>
  3. #ifdef _KERNEL_
  4. # include <kernel/types.h>
  5. #else
  6. # include <stdint.h>
  7. #endif
  8. _Begin_C_Header
  9. #define TERM_BUF_LEN 128
  10. /* A terminal cell represents a single character on screen */
  11. typedef struct {
  12. uint32_t c; /* codepoint */
  13. uint32_t fg; /* background indexed color */
  14. uint32_t bg; /* foreground indexed color */
  15. uint32_t flags; /* other flags */
  16. } term_cell_t;
  17. typedef struct {
  18. void (*writer)(char);
  19. void (*set_color)(uint32_t, uint32_t);
  20. void (*set_csr)(int,int);
  21. int (*get_csr_x)(void);
  22. int (*get_csr_y)(void);
  23. void (*set_cell)(int,int,uint32_t);
  24. void (*cls)(int);
  25. void (*scroll)(int);
  26. void (*redraw_cursor)(void);
  27. void (*input_buffer_stuff)(char *);
  28. void (*set_title)(char *);
  29. void (*set_cell_contents)(int,int,char *);
  30. int (*get_cell_width)(void);
  31. int (*get_cell_height)(void);
  32. void (*set_csr_on)(int);
  33. void (*switch_buffer)(int);
  34. void (*insert_delete_lines)(int);
  35. } term_callbacks_t;
  36. typedef struct {
  37. uint16_t x; /* Current cursor location */
  38. uint16_t y; /* " " " */
  39. uint16_t save_x; /* Last cursor save */
  40. uint16_t save_y;
  41. uint32_t width; /* Terminal width */
  42. uint32_t height; /* " height */
  43. uint32_t fg; /* Current foreground color */
  44. uint32_t bg; /* Current background color */
  45. uint8_t flags; /* Bright, etc. */
  46. uint8_t escape; /* Escape status */
  47. uint8_t box;
  48. uint8_t buflen; /* Buffer Length */
  49. char buffer[TERM_BUF_LEN]; /* Previous buffer */
  50. term_callbacks_t * callbacks;
  51. int volatile lock;
  52. uint8_t mouse_on;
  53. uint32_t img_collected;
  54. uint32_t img_size;
  55. char * img_data;
  56. } term_state_t;
  57. /* Triggers escape mode. */
  58. #define ANSI_ESCAPE 27
  59. /* Escape verify */
  60. #define ANSI_BRACKET '['
  61. #define ANSI_BRACKET_RIGHT ']'
  62. #define ANSI_OPEN_PAREN '('
  63. /* Anything in this range (should) exit escape mode. */
  64. #define ANSI_LOW 'A'
  65. #define ANSI_HIGH 'z'
  66. /* Escape commands */
  67. #define ANSI_CUU 'A' /* CUrsor Up */
  68. #define ANSI_CUD 'B' /* CUrsor Down */
  69. #define ANSI_CUF 'C' /* CUrsor Forward */
  70. #define ANSI_CUB 'D' /* CUrsor Back */
  71. #define ANSI_CNL 'E' /* Cursor Next Line */
  72. #define ANSI_CPL 'F' /* Cursor Previous Line */
  73. #define ANSI_CHA 'G' /* Cursor Horizontal Absolute */
  74. #define ANSI_CUP 'H' /* CUrsor Position */
  75. #define ANSI_ED 'J' /* Erase Data */
  76. #define ANSI_EL 'K' /* Erase in Line */
  77. #define ANSI_SU 'S' /* Scroll Up */
  78. #define ANSI_SD 'T' /* Scroll Down */
  79. #define ANSI_HVP 'f' /* Horizontal & Vertical Pos. */
  80. #define ANSI_SGR 'm' /* Select Graphic Rendition */
  81. #define ANSI_DSR 'n' /* Device Status Report */
  82. #define ANSI_SCP 's' /* Save Cursor Position */
  83. #define ANSI_RCP 'u' /* Restore Cursor Position */
  84. #define ANSI_HIDE 'l' /* DECTCEM - Hide Cursor */
  85. #define ANSI_SHOW 'h' /* DECTCEM - Show Cursor */
  86. #define ANSI_IL 'L' /* Insert Line(s) */
  87. #define ANSI_DL 'M' /* Delete Line(s) */
  88. /* Display flags */
  89. #define ANSI_BOLD 0x01
  90. #define ANSI_UNDERLINE 0x02
  91. #define ANSI_ITALIC 0x04
  92. #define ANSI_ALTFONT 0x08 /* Character should use alternate font */
  93. #define ANSI_SPECBG 0x10
  94. #define ANSI_BORDER 0x20
  95. #define ANSI_WIDE 0x40 /* Character is double width */
  96. #define ANSI_CROSS 0x80 /* And that's all I'm going to support (for now) */
  97. #define ANSI_EXT_IMG 0x100 /* Cell is actually an image, use fg color as pointer */
  98. #define ANSI_EXT_IOCTL 'z' /* These are special escapes only we support */
  99. /* Default color settings */
  100. #define TERM_DEFAULT_FG 0x07 /* Index of default foreground */
  101. #define TERM_DEFAULT_BG 0x10 /* Index of default background */
  102. #define TERM_DEFAULT_FLAGS 0x00 /* Default flags for a cell */
  103. #define TERM_DEFAULT_OPAC 0xF2 /* For background, default transparency */
  104. #define TERMEMU_MOUSE_ENABLE 0x01
  105. #define TERMEMU_MOUSE_DRAG 0x02
  106. #define TERMEMU_MOUSE_SGR 0x04
  107. /* TODO: _MOUSE_UTF8 0x08 */
  108. /* TODO: _MOUSE_URXVT 0x10 */
  109. extern term_state_t * ansi_init(term_state_t * s, int w, int y, term_callbacks_t * callbacks_in);
  110. extern void ansi_put(term_state_t * s, char c);
  111. _End_C_Header