vt100.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /** @file vt100.h
  2. *
  3. */
  4. #ifndef _tinyrl_vt100_h
  5. #define _tinyrl_vt100_h
  6. #include <stdio.h>
  7. #include <stdarg.h>
  8. #include <faux/faux.h>
  9. typedef struct vt100_s vt100_t;
  10. #define VT100_HOTKEY_MAP_LEN 32
  11. // Key codes
  12. #define KEY_NUL 0 // ^@ Null character
  13. #define KEY_SOH 1 // ^A Start of heading, = console interrupt
  14. #define KEY_STX 2 // ^B Start of text, maintenance mode on HP console
  15. #define KEY_ETX 3 // ^C End of text
  16. #define KEY_EOT 4 // ^D End of transmission, not the same as ETB
  17. #define KEY_ENQ 5 // ^E Enquiry, goes with ACK; old HP flow control
  18. #define KEY_ACK 6 // ^F Acknowledge, clears ENQ logon hand
  19. #define KEY_BEL 7 // ^G Bell, rings the bell
  20. #define KEY_BS 8 // ^H Backspace, works on HP terminals/computers
  21. #define KEY_HT 9 // ^I Horizontal tab, move to next tab stop
  22. #define KEY_LF 10 // ^J Line Feed
  23. #define KEY_VT 11 // ^K Vertical tab
  24. #define KEY_FF 12 // ^L Form Feed, page eject
  25. #define KEY_CR 13 // ^M Carriage Return
  26. #define KEY_SO 14 // ^N Shift Out, alternate character set
  27. #define KEY_SI 15 // ^O Shift In, resume defaultn character set
  28. #define KEY_DLE 16 // ^P Data link escape
  29. #define KEY_DC1 17 // ^Q XON, with XOFF to pause listings; "okay to send"
  30. #define KEY_DC2 18 // ^R Device control 2, block-mode flow control
  31. #define KEY_DC3 19 // ^S XOFF, with XON is TERM=18 flow control
  32. #define KEY_DC4 20 // ^T Device control 4
  33. #define KEY_NAK 21 // ^U Negative acknowledge
  34. #define KEY_SYN 22 // ^V Synchronous idle
  35. #define KEY_ETB 23 // ^W End transmission block, not the same as EOT
  36. #define KEY_CAN 24 // ^X Cancel line, MPE echoes !!!
  37. #define KEY_EM 25 // ^Y End of medium, Control-Y interrupt
  38. #define KEY_SUB 26 // ^Z Substitute
  39. #define KEY_ESC 27 // ^[ Escape, next character is not echoed
  40. #define KEY_FS 28 // ^\ File separator
  41. #define KEY_GS 29 // ^] Group separator
  42. #define KEY_RS 30 // ^^ Record separator, block-mode terminator
  43. #define KEY_US 31 // ^_ Unit separator
  44. #define KEY_DEL 127 // Delete (not a real control character)
  45. // Types of escape code
  46. typedef enum {
  47. VT100_UNKNOWN, // Undefined escape sequence
  48. VT100_CURSOR_UP, // Move the cursor up
  49. VT100_CURSOR_DOWN, // Move the cursor down
  50. VT100_CURSOR_LEFT, // Move the cursor left
  51. VT100_CURSOR_RIGHT, // Move the cursor right
  52. VT100_HOME, // Move the cursor to the beginning of the line
  53. VT100_END, // Move the cursor to the end of the line
  54. VT100_INSERT, // No action at the moment
  55. VT100_DELETE, // Delete character on the right
  56. VT100_PGUP, // No action at the moment
  57. VT100_PGDOWN // No action at the moment
  58. } vt100_esc_e;
  59. C_DECL_BEGIN
  60. vt100_t *vt100_new(FILE *istream, FILE *ostream);
  61. void vt100_free(vt100_t *vt100);
  62. FILE *vt100_istream(const vt100_t *vt100);
  63. void vt100_set_istream(vt100_t *vt100, FILE *istream);
  64. FILE *vt100_ostream(const vt100_t *vt100);
  65. void vt100_set_ostream(vt100_t *vt100, FILE *ostream);
  66. void vt100_winsize(const vt100_t *vt100, size_t *width, size_t *height);
  67. size_t vt100_width(const vt100_t *vt100);
  68. size_t vt100_height(const vt100_t *vt100);
  69. int vt100_printf(const vt100_t *vt100, const char *fmt, ...);
  70. int vt100_vprintf(const vt100_t *vt100, const char *fmt, va_list args);
  71. int vt100_oflush(const vt100_t *vt100);
  72. int vt100_ierror(const vt100_t *vt100);
  73. int vt100_oerror(const vt100_t *vt100);
  74. int vt100_ieof(const vt100_t *vt100);
  75. int vt100_getchar(const vt100_t *vt100, unsigned char *c);
  76. vt100_esc_e vt100_esc_decode(const char *esc_seq);
  77. ssize_t vt100_hotkey_decode(const char *hotkey);
  78. void vt100_ding(const vt100_t *vt100);
  79. void vt100_attr_reset(const vt100_t *vt100);
  80. void vt100_attr_bright(const vt100_t *vt100);
  81. void vt100_attr_dim(const vt100_t *vt100);
  82. void vt100_attr_underscore(const vt100_t *vt100);
  83. void vt100_attr_blink(const vt100_t *vt100);
  84. void vt100_attr_reverse(const vt100_t *vt100);
  85. void vt100_attr_hidden(const vt100_t *vt100);
  86. void vt100_erase_line(const vt100_t *vt100);
  87. void vt100_clear_screen(const vt100_t *vt100);
  88. void vt100_cursor_back(const vt100_t *vt100, size_t count);
  89. void vt100_cursor_forward(const vt100_t *vt100, size_t count);
  90. void vt100_cursor_up(const vt100_t *vt100, size_t count);
  91. void vt100_cursor_down(const vt100_t *vt100, size_t count);
  92. void vt100_scroll_up(const vt100_t *instance);
  93. void vt100_scroll_down(const vt100_t *instance);
  94. void vt100_next_line(const vt100_t *instance);
  95. void vt100_cursor_home(const vt100_t *vt100);
  96. void vt100_cursor_save(const vt100_t *vt100);
  97. void vt100_cursor_restore(const vt100_t *vt100);
  98. void vt100_erase(const vt100_t *vt100, size_t count);
  99. void vt100_erase_down(const vt100_t *vt100);
  100. C_DECL_END
  101. #endif // _tinyrl_vt100_h