termemu.h 3.8 KB

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