ansi_def.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @file ansi_def.h
  3. * @author Ji Youzhou
  4. * @version V0.1
  5. * @date 11 June 2020
  6. * @brief [brief]
  7. * *****************************************************************************
  8. * @attention
  9. *
  10. * MIT License
  11. *
  12. * Copyright (C) 2019 Ji Youzhou. or its affiliates. All Rights Reserved.
  13. *
  14. * Permission is hereby granted, free of charge, to any person obtaining a copy
  15. * of this software and associated documentation files (the "Software"), to deal
  16. * in the Software without restriction, including without limitation the rights
  17. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. * copies of the Software, and to permit persons to whom the Software is
  19. * furnished to do so, subject to the following conditions:
  20. *
  21. * The above copyright notice and this permission notice shall be included in all
  22. * copies or substantial portions of the Software.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. * Change Logs:
  33. * Date Author Notes
  34. * 2020-6-11 Ji Youzhou first version
  35. *
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __ansi_def_h
  39. #define __ansi_def_h
  40. #ifdef __cplusplus
  41. extern "C"
  42. {
  43. #endif
  44. /* Includes ------------------------------------------------------------------*/
  45. #include "nr_micro_shell_config.h"
  46. #define NR_ANSI_CTRL_MAX_LEN 20
  47. #define NR_ANSI_MAX_EX_DATA_NUM 1
  48. enum
  49. {
  50. ANSI_ENABLE_SHOW,
  51. ANSI_DISABLE_SHOW
  52. };
  53. typedef struct nr_ansi_struct
  54. {
  55. short p;
  56. unsigned int counter;
  57. char current_line[NR_ANSI_LINE_SIZE];
  58. char combine_buf[NR_ANSI_CTRL_MAX_LEN];
  59. char cmd_num;
  60. char combine_state;
  61. } ansi_st;
  62. typedef void (*ansi_fun_t)(ansi_st *);
  63. #define NR_ANSI_SET_TEXT(cmd) ((const char *)"\033["##cmd##"m") /** the form of set text font */
  64. /** set the color of background */
  65. #define NR_ANSI_BBLACK "40"
  66. #define NR_ANSI_BRED "41"
  67. #define NR_ANSI_BGREEN "42"
  68. #define NR_ANSI_BGRAY "43"
  69. #define NR_ANSI_BBLUE "44"
  70. #define NR_ANSI_BPURPLE "45"
  71. #define NR_ANSI_BAQUAM "46"
  72. #define NR_ANSI_BWHITE "47"
  73. /** set the color of character */
  74. #define NR_ANSI_FBLACK "30"
  75. #define NR_ANSI_FRED "31"
  76. #define NR_ANSI_FGREEN "32"
  77. #define NR_ANSI_FGRAY "33"
  78. #define NR_ANSI_FBLUE "34"
  79. #define NR_ANSI_FPURPLE "35"
  80. #define NR_ANSI_FAQUAM "36"
  81. #define NR_ANSI_FWHITE "37"
  82. /** special effect */
  83. #define NR_ANSI_NORMAL "0"
  84. #define NR_ANSI_BRIGHT "1"
  85. #define NR_ANSI_UNDERLINE "4"
  86. #define NR_ANSI_FLASH "5"
  87. #define NR_ANSI_INVERSE "7"
  88. #define NR_ANSI_INVISABLE "8"
  89. /****************************************************/
  90. /** clear code */
  91. #define NR_ANSI_CLEAR_RIGHT "\033[K"
  92. #define NR_ANSI_CLEAR_LEFT "\033[1K"
  93. #define NR_ANSI_CLEAR_WHOLE "\033[2K"
  94. #define NR_ANSI_CLEAR_SCREEN "\033[2J"
  95. #define NR_ANSI_HIDE_COURSER "\033[?25l"
  96. #define NR_ANSI_SHOW_COURSER "\033[?25h"
  97. #define NR_ANSI_SET_FONT(cmd) ((const char *)"\033["#cmd"I")
  98. #define NR_ANSI_CLR_R_NCHAR(cmd) ((const char *)"\033["#cmd"X")
  99. #define NR_ANSI_CLR_R_MV_L_NCHAR(cmd) ((const char *)"\033["#cmd"P")
  100. /** move course code */
  101. #define NR_ANSI_MV_L_N(n) ((const char *)"\033["#n"D")
  102. #define NR_ANSI_MV_R_N(n) ((const char *)"\033["#n"C")
  103. #define NR_ANSI_NORMAL "0"
  104. #define NR_ANSI_SONG "1"
  105. #define NR_ANSI_HEI "2"
  106. #define NR_ANSI_KAI "3"
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif
  111. /******************* (C) COPYRIGHT 2019 Ji Youzhou *****END OF FILE*****************/