You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ansiesc.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef _GPXE_ANSIESC_H
  2. #define _GPXE_ANSIESC_H
  3. /** @file
  4. *
  5. * ANSI escape sequences
  6. *
  7. * ANSI X3.64 (aka ECMA-48 or ISO/IEC 6429, available from
  8. * http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf)
  9. * defines escape sequences consisting of:
  10. *
  11. * A Control Sequence Introducer (CSI)
  12. *
  13. * Zero or more Parameter Bytes (P)
  14. *
  15. * Zero or more Intermediate Bytes (I)
  16. *
  17. * A Final Byte (F)
  18. *
  19. * The CSI consists of ESC (0x1b) followed by "[" (0x5b). The
  20. * Parameter Bytes, for a standardised (i.e. not private or
  21. * experimental) sequence, consist of a list of ASCII decimal integers
  22. * separated by semicolons. The Intermediate Bytes (in the range 0x20
  23. * to 0x2f) and the Final Byte (in the range 0x40 to 0x4f) determine
  24. * the control function.
  25. *
  26. */
  27. /** A handler for an escape sequence */
  28. struct ansiesc_handler {
  29. /** The control function identifier
  30. *
  31. * The control function identifier consists of the
  32. * Intermediate Bytes (if any) and the Final Byte. In
  33. * practice, no more than one immediate byte is ever used, so
  34. * the byte combination can be efficiently expressed as a
  35. * single integer, in the obvious way (with the Final Byte
  36. * being the least significant byte).
  37. */
  38. unsigned int function;
  39. /** Handle escape sequence
  40. *
  41. * @v count Parameter count
  42. * @v params Parameter list
  43. *
  44. * A negative parameter value indicates that the parameter was
  45. * omitted and that the default value for this control
  46. * function should be used.
  47. *
  48. * Since all parameters are optional, there is no way to
  49. * distinguish between "zero parameters" and "single parameter
  50. * omitted". Consequently, the parameter list will always
  51. * contain at least one item.
  52. */
  53. void ( * handle ) ( unsigned int count, int params[] );
  54. };
  55. /** Maximum number of parameters within a single escape sequence */
  56. #define ANSIESC_MAX_PARAMS 4
  57. /**
  58. * ANSI escape sequence context
  59. *
  60. * This provides temporary storage for processing escape sequences,
  61. * and points to the list of escape sequence handlers.
  62. */
  63. struct ansiesc_context {
  64. /** Array of handlers
  65. *
  66. * Must be terminated by a handler with @c function set to
  67. * zero.
  68. */
  69. struct ansiesc_handler *handlers;
  70. /** Parameter count
  71. *
  72. * Will be zero when not currently in an escape sequence.
  73. */
  74. unsigned int count;
  75. /** Parameter list */
  76. int params[ANSIESC_MAX_PARAMS];
  77. /** Control function identifier */
  78. unsigned int function;
  79. };
  80. /** Escape character */
  81. #define ESC 0x1b
  82. /** Control Sequence Introducer */
  83. #define CSI "\033["
  84. /**
  85. * @defgroup ansifuncs ANSI escape sequence function identifiers
  86. * @{
  87. */
  88. /** Cursor position */
  89. #define ANSIESC_CUP 'H'
  90. /** Erase in page */
  91. #define ANSIESC_ED 'J'
  92. /** Erase from cursor to end of page */
  93. #define ANSIESC_ED_TO_END 0
  94. /** Erase from start of page to cursor */
  95. #define ANSIESC_ED_FROM_START 1
  96. /** Erase whole page */
  97. #define ANSIESC_ED_ALL 2
  98. /** Select graphic rendition */
  99. #define ANSIESC_SGR 'm'
  100. /** @} */
  101. extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
  102. #endif /* _GPXE_ANSIESC_H */