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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. FILE_LICENCE ( GPL2_OR_LATER );
  28. /** A handler for an escape sequence */
  29. struct ansiesc_handler {
  30. /** The control function identifier
  31. *
  32. * The control function identifier consists of the
  33. * Intermediate Bytes (if any) and the Final Byte. In
  34. * practice, no more than one immediate byte is ever used, so
  35. * the byte combination can be efficiently expressed as a
  36. * single integer, in the obvious way (with the Final Byte
  37. * being the least significant byte).
  38. */
  39. unsigned int function;
  40. /** Handle escape sequence
  41. *
  42. * @v count Parameter count
  43. * @v params Parameter list
  44. *
  45. * A negative parameter value indicates that the parameter was
  46. * omitted and that the default value for this control
  47. * function should be used.
  48. *
  49. * Since all parameters are optional, there is no way to
  50. * distinguish between "zero parameters" and "single parameter
  51. * omitted". Consequently, the parameter list will always
  52. * contain at least one item.
  53. */
  54. void ( * handle ) ( unsigned int count, int params[] );
  55. };
  56. /** Maximum number of parameters within a single escape sequence */
  57. #define ANSIESC_MAX_PARAMS 4
  58. /**
  59. * ANSI escape sequence context
  60. *
  61. * This provides temporary storage for processing escape sequences,
  62. * and points to the list of escape sequence handlers.
  63. */
  64. struct ansiesc_context {
  65. /** Array of handlers
  66. *
  67. * Must be terminated by a handler with @c function set to
  68. * zero.
  69. */
  70. struct ansiesc_handler *handlers;
  71. /** Parameter count
  72. *
  73. * Will be zero when not currently in an escape sequence.
  74. */
  75. unsigned int count;
  76. /** Parameter list */
  77. int params[ANSIESC_MAX_PARAMS];
  78. /** Control function identifier */
  79. unsigned int function;
  80. };
  81. /** Escape character */
  82. #define ESC 0x1b
  83. /** Control Sequence Introducer */
  84. #define CSI "\033["
  85. /**
  86. * @defgroup ansifuncs ANSI escape sequence function identifiers
  87. * @{
  88. */
  89. /** Cursor position */
  90. #define ANSIESC_CUP 'H'
  91. /** Erase in page */
  92. #define ANSIESC_ED 'J'
  93. /** Erase from cursor to end of page */
  94. #define ANSIESC_ED_TO_END 0
  95. /** Erase from start of page to cursor */
  96. #define ANSIESC_ED_FROM_START 1
  97. /** Erase whole page */
  98. #define ANSIESC_ED_ALL 2
  99. /** Select graphic rendition */
  100. #define ANSIESC_SGR 'm'
  101. /** @} */
  102. extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
  103. #endif /* _GPXE_ANSIESC_H */