Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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