vt100.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * vt100.h
  3. *
  4. * A simple class representing a vt100 terminal
  5. */
  6. /**
  7. \ingroup tinyrl
  8. \defgroup tinyrl_vt100 vt100
  9. @{
  10. \brief A simple class for controlling and interacting with a VT100 compatible
  11. terminal.
  12. This class has been implemented pragmatically in an as needed fashion, so
  13. doesn't support all the features of a VT100 terminal.
  14. */
  15. #ifndef _tinyrl_vt100_h
  16. #define _tinyrl_vt100_h
  17. #include <stdio.h>
  18. #include <stdarg.h>
  19. #include "lub/c_decl.h"
  20. #include "lub/types.h"
  21. _BEGIN_C_DECL typedef struct _tinyrl_vt100 tinyrl_vt100_t;
  22. /* define the Key codes */
  23. #define KEY_NUL 0 /**< ^@ Null character */
  24. #define KEY_SOH 1 /**< ^A Start of heading, = console interrupt */
  25. #define KEY_STX 2 /**< ^B Start of text, maintenance mode on HP console */
  26. #define KEY_ETX 3 /**< ^C End of text */
  27. #define KEY_EOT 4 /**< ^D End of transmission, not the same as ETB */
  28. #define KEY_ENQ 5 /**< ^E Enquiry, goes with ACK; old HP flow control */
  29. #define KEY_ACK 6 /**< ^F Acknowledge, clears ENQ logon hand */
  30. #define KEY_BEL 7 /**< ^G Bell, rings the bell... */
  31. #define KEY_BS 8 /**< ^H Backspace, works on HP terminals/computers */
  32. #define KEY_HT 9 /**< ^I Horizontal tab, move to next tab stop */
  33. #define KEY_LF 10 /**< ^J Line Feed */
  34. #define KEY_VT 11 /**< ^K Vertical tab */
  35. #define KEY_FF 12 /**< ^L Form Feed, page eject */
  36. #define KEY_CR 13 /**< ^M Carriage Return*/
  37. #define KEY_SO 14 /**< ^N Shift Out, alternate character set */
  38. #define KEY_SI 15 /**< ^O Shift In, resume defaultn character set */
  39. #define KEY_DLE 16 /**< ^P Data link escape */
  40. #define KEY_DC1 17 /**< ^Q XON, with XOFF to pause listings; "okay to send". */
  41. #define KEY_DC2 18 /**< ^R Device control 2, block-mode flow control */
  42. #define KEY_DC3 19 /**< ^S XOFF, with XON is TERM=18 flow control */
  43. #define KEY_DC4 20 /**< ^T Device control 4 */
  44. #define KEY_NAK 21 /**< ^U Negative acknowledge */
  45. #define KEY_SYN 22 /**< ^V Synchronous idle */
  46. #define KEY_ETB 23 /**< ^W End transmission block, not the same as EOT */
  47. #define KEY_CAN 24 /**< ^X Cancel line, MPE echoes !!! */
  48. #define KEY_EM 25 /**< ^Y End of medium, Control-Y interrupt */
  49. #define KEY_SUB 26 /**< ^Z Substitute */
  50. #define KEY_ESC 27 /**< ^[ Escape, next character is not echoed */
  51. #define KEY_FS 28 /**< ^\ File separator */
  52. #define KEY_GS 29 /**< ^] Group separator */
  53. #define KEY_RS 30 /**< ^^ Record separator, block-mode terminator */
  54. #define KEY_US 31 /**< ^_ Unit separator */
  55. #define KEY_DEL 127 /**< Delete (not a real control character...) */
  56. /**
  57. * This enumeration is used to identify the types of escape code
  58. */
  59. typedef enum {
  60. tinyrl_vt100_UNKNOWN, /**< Undefined escape sequence */
  61. tinyrl_vt100_CURSOR_UP, /**< Move the cursor up */
  62. tinyrl_vt100_CURSOR_DOWN, /**< Move the cursor down */
  63. tinyrl_vt100_CURSOR_LEFT, /**< Move the cursor left */
  64. tinyrl_vt100_CURSOR_RIGHT, /**< Move the cursor right */
  65. tinyrl_vt100_HOME, /**< Move the cursor to the beginning of the line */
  66. tinyrl_vt100_END, /**< Move the cursor to the end of the line */
  67. tinyrl_vt100_INSERT, /**< No action at the moment */
  68. tinyrl_vt100_DELETE, /**< Delete character on the right */
  69. tinyrl_vt100_PGUP, /**< No action at the moment */
  70. tinyrl_vt100_PGDOWN /**< No action at the moment */
  71. } tinyrl_vt100_escape_e;
  72. /* Return values from vt100_getchar() */
  73. #define VT100_EOF -1
  74. #define VT100_TIMEOUT -2
  75. #define VT100_ERR -3
  76. extern tinyrl_vt100_t *tinyrl_vt100_new(FILE * instream, FILE * outstream);
  77. extern void tinyrl_vt100_delete(tinyrl_vt100_t * instance);
  78. /*lint -esym(534,tinyrl_vt100_printf) Ignoring return value of function */
  79. extern int tinyrl_vt100_printf(const tinyrl_vt100_t * instance, const char *fmt, ...
  80. );
  81. extern int
  82. tinyrl_vt100_vprintf(const tinyrl_vt100_t * instance,
  83. const char *fmt, va_list args);
  84. extern int tinyrl_vt100_oflush(const tinyrl_vt100_t * instance);
  85. extern int tinyrl_vt100_ierror(const tinyrl_vt100_t * instance);
  86. extern int tinyrl_vt100_oerror(const tinyrl_vt100_t * instance);
  87. extern int tinyrl_vt100_ieof(const tinyrl_vt100_t * instance);
  88. extern int tinyrl_vt100_getchar(const tinyrl_vt100_t * instance);
  89. extern unsigned tinyrl_vt100__get_width(const tinyrl_vt100_t * instance);
  90. extern unsigned tinyrl_vt100__get_height(const tinyrl_vt100_t * instance);
  91. extern void tinyrl_vt100__set_timeout(tinyrl_vt100_t *instance, int timeout);
  92. extern void
  93. tinyrl_vt100__set_istream(tinyrl_vt100_t * instance, FILE * istream);
  94. extern FILE *tinyrl_vt100__get_istream(const tinyrl_vt100_t * instance);
  95. extern FILE *tinyrl_vt100__get_ostream(const tinyrl_vt100_t * instance);
  96. extern tinyrl_vt100_escape_e
  97. tinyrl_vt100_escape_decode(const tinyrl_vt100_t * instance, const char *esc_seq);
  98. extern void tinyrl_vt100_ding(const tinyrl_vt100_t * instance);
  99. extern void tinyrl_vt100_attribute_reset(const tinyrl_vt100_t * instance);
  100. extern void tinyrl_vt100_attribute_bright(const tinyrl_vt100_t * instance);
  101. extern void tinyrl_vt100_attribute_dim(const tinyrl_vt100_t * instance);
  102. extern void tinyrl_vt100_attribute_underscore(const tinyrl_vt100_t * instance);
  103. extern void tinyrl_vt100_attribute_blink(const tinyrl_vt100_t * instance);
  104. extern void tinyrl_vt100_attribute_reverse(const tinyrl_vt100_t * instance);
  105. extern void tinyrl_vt100_attribute_hidden(const tinyrl_vt100_t * instance);
  106. extern void tinyrl_vt100_erase_line(const tinyrl_vt100_t * instance);
  107. extern void tinyrl_vt100_clear_screen(const tinyrl_vt100_t * instance);
  108. extern void
  109. tinyrl_vt100_cursor_back(const tinyrl_vt100_t * instance, unsigned count);
  110. extern void
  111. tinyrl_vt100_cursor_forward(const tinyrl_vt100_t * instance, unsigned count);
  112. extern void
  113. tinyrl_vt100_cursor_up(const tinyrl_vt100_t * instance, unsigned count);
  114. extern void
  115. tinyrl_vt100_cursor_down(const tinyrl_vt100_t * instance, unsigned count);
  116. extern void tinyrl_vt100_scroll_up(const tinyrl_vt100_t *instance);
  117. extern void tinyrl_vt100_scroll_down(const tinyrl_vt100_t *instance);
  118. extern void tinyrl_vt100_next_line(const tinyrl_vt100_t *instance);
  119. extern void tinyrl_vt100_cursor_home(const tinyrl_vt100_t * instance);
  120. extern void tinyrl_vt100_cursor_save(const tinyrl_vt100_t * instance);
  121. extern void tinyrl_vt100_cursor_restore(const tinyrl_vt100_t * instance);
  122. extern void tinyrl_vt100_erase(const tinyrl_vt100_t * instance, unsigned count);
  123. extern void tinyrl_vt100_erase_down(const tinyrl_vt100_t * instance);
  124. _END_C_DECL
  125. #endif /* _tinyrl_vt100_h */
  126. /** @} tinyrl_vt100 */