vt100.h 4.5 KB

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