ansi_escape.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. /** \ingroup group_board
  27. * \defgroup group_ansi_esc ANSI Escape Code
  28. * @{ */
  29. #ifndef _TUSB_ANSI_ESC_CODE_H_
  30. #define _TUSB_ANSI_ESC_CODE_H_
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #define CSI_CODE(seq) "\33[" seq
  35. #define CSI_SGR(x) CSI_CODE(#x) "m"
  36. //------------- Cursor movement -------------//
  37. /** \defgroup group_ansi_cursor Cursor Movement
  38. * @{ */
  39. #define ANSI_CURSOR_UP(n) CSI_CODE(#n "A") ///< Move cursor up
  40. #define ANSI_CURSOR_DOWN(n) CSI_CODE(#n "B") ///< Move cursor down
  41. #define ANSI_CURSOR_FORWARD(n) CSI_CODE(#n "C") ///< Move cursor forward
  42. #define ANSI_CURSOR_BACKWARD(n) CSI_CODE(#n "D") ///< Move cursor backward
  43. #define ANSI_CURSOR_LINE_DOWN(n) CSI_CODE(#n "E") ///< Move cursor to the beginning of the line (n) down
  44. #define ANSI_CURSOR_LINE_UP(n) CSI_CODE(#n "F") ///< Move cursor to the beginning of the line (n) up
  45. #define ANSI_CURSOR_POSITION(n, m) CSI_CODE(#n ";" #m "H") ///< Move cursor to position (n, m)
  46. /** @} */
  47. //------------- Screen -------------//
  48. /** \defgroup group_ansi_screen Screen Control
  49. * @{ */
  50. #define ANSI_ERASE_SCREEN(n) CSI_CODE(#n "J") ///< Erase the screen
  51. #define ANSI_ERASE_LINE(n) CSI_CODE(#n "K") ///< Erase the line (n)
  52. #define ANSI_SCROLL_UP(n) CSI_CODE(#n "S") ///< Scroll the whole page up (n) lines
  53. #define ANSI_SCROLL_DOWN(n) CSI_CODE(#n "T") ///< Scroll the whole page down (n) lines
  54. /** @} */
  55. //------------- Text Color -------------//
  56. /** \defgroup group_ansi_text Text Color
  57. * @{ */
  58. #define ANSI_TEXT_BLACK CSI_SGR(30)
  59. #define ANSI_TEXT_RED CSI_SGR(31)
  60. #define ANSI_TEXT_GREEN CSI_SGR(32)
  61. #define ANSI_TEXT_YELLOW CSI_SGR(33)
  62. #define ANSI_TEXT_BLUE CSI_SGR(34)
  63. #define ANSI_TEXT_MAGENTA CSI_SGR(35)
  64. #define ANSI_TEXT_CYAN CSI_SGR(36)
  65. #define ANSI_TEXT_WHITE CSI_SGR(37)
  66. #define ANSI_TEXT_DEFAULT CSI_SGR(39)
  67. /** @} */
  68. //------------- Background Color -------------//
  69. /** \defgroup group_ansi_background Background Color
  70. * @{ */
  71. #define ANSI_BG_BLACK CSI_SGR(40)
  72. #define ANSI_BG_RED CSI_SGR(41)
  73. #define ANSI_BG_GREEN CSI_SGR(42)
  74. #define ANSI_BG_YELLOW CSI_SGR(43)
  75. #define ANSI_BG_BLUE CSI_SGR(44)
  76. #define ANSI_BG_MAGENTA CSI_SGR(45)
  77. #define ANSI_BG_CYAN CSI_SGR(46)
  78. #define ANSI_BG_WHITE CSI_SGR(47)
  79. #define ANSI_BG_DEFAULT CSI_SGR(49)
  80. /** @} */
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* _TUSB_ANSI_ESC_CODE_H_ */
  85. /** @} */