Terminal.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #ifndef cmsys_Terminal_h
  4. #define cmsys_Terminal_h
  5. #include <cmsys/Configure.h>
  6. #include <stdio.h> /* For file stream type FILE. */
  7. /* Redefine all public interface symbol names to be in the proper
  8. namespace. These macros are used internally to kwsys only, and are
  9. not visible to user code. Use kwsysHeaderDump.pl to reproduce
  10. these macros after making changes to the interface. */
  11. #if !defined(KWSYS_NAMESPACE)
  12. #define kwsys_ns(x) cmsys##x
  13. #define kwsysEXPORT cmsys_EXPORT
  14. #endif
  15. #if !cmsys_NAME_IS_KWSYS
  16. #define kwsysTerminal_cfprintf kwsys_ns(Terminal_cfprintf)
  17. #define kwsysTerminal_Color_e kwsys_ns(Terminal_Color_e)
  18. #define kwsysTerminal_Color_Normal kwsys_ns(Terminal_Color_Normal)
  19. #define kwsysTerminal_Color_ForegroundBlack \
  20. kwsys_ns(Terminal_Color_ForegroundBlack)
  21. #define kwsysTerminal_Color_ForegroundRed \
  22. kwsys_ns(Terminal_Color_ForegroundRed)
  23. #define kwsysTerminal_Color_ForegroundGreen \
  24. kwsys_ns(Terminal_Color_ForegroundGreen)
  25. #define kwsysTerminal_Color_ForegroundYellow \
  26. kwsys_ns(Terminal_Color_ForegroundYellow)
  27. #define kwsysTerminal_Color_ForegroundBlue \
  28. kwsys_ns(Terminal_Color_ForegroundBlue)
  29. #define kwsysTerminal_Color_ForegroundMagenta \
  30. kwsys_ns(Terminal_Color_ForegroundMagenta)
  31. #define kwsysTerminal_Color_ForegroundCyan \
  32. kwsys_ns(Terminal_Color_ForegroundCyan)
  33. #define kwsysTerminal_Color_ForegroundWhite \
  34. kwsys_ns(Terminal_Color_ForegroundWhite)
  35. #define kwsysTerminal_Color_ForegroundMask \
  36. kwsys_ns(Terminal_Color_ForegroundMask)
  37. #define kwsysTerminal_Color_BackgroundBlack \
  38. kwsys_ns(Terminal_Color_BackgroundBlack)
  39. #define kwsysTerminal_Color_BackgroundRed \
  40. kwsys_ns(Terminal_Color_BackgroundRed)
  41. #define kwsysTerminal_Color_BackgroundGreen \
  42. kwsys_ns(Terminal_Color_BackgroundGreen)
  43. #define kwsysTerminal_Color_BackgroundYellow \
  44. kwsys_ns(Terminal_Color_BackgroundYellow)
  45. #define kwsysTerminal_Color_BackgroundBlue \
  46. kwsys_ns(Terminal_Color_BackgroundBlue)
  47. #define kwsysTerminal_Color_BackgroundMagenta \
  48. kwsys_ns(Terminal_Color_BackgroundMagenta)
  49. #define kwsysTerminal_Color_BackgroundCyan \
  50. kwsys_ns(Terminal_Color_BackgroundCyan)
  51. #define kwsysTerminal_Color_BackgroundWhite \
  52. kwsys_ns(Terminal_Color_BackgroundWhite)
  53. #define kwsysTerminal_Color_BackgroundMask \
  54. kwsys_ns(Terminal_Color_BackgroundMask)
  55. #define kwsysTerminal_Color_ForegroundBold \
  56. kwsys_ns(Terminal_Color_ForegroundBold)
  57. #define kwsysTerminal_Color_BackgroundBold \
  58. kwsys_ns(Terminal_Color_BackgroundBold)
  59. #define kwsysTerminal_Color_AssumeTTY kwsys_ns(Terminal_Color_AssumeTTY)
  60. #define kwsysTerminal_Color_AssumeVT100 kwsys_ns(Terminal_Color_AssumeVT100)
  61. #define kwsysTerminal_Color_AttributeMask \
  62. kwsys_ns(Terminal_Color_AttributeMask)
  63. #endif
  64. #if defined(__cplusplus)
  65. extern "C" {
  66. #endif
  67. /**
  68. * Write colored and formatted text to a stream. Color is used only
  69. * for streams supporting it. The color specification is constructed
  70. * by bitwise-OR-ing enumeration values. At most one foreground and
  71. * one background value may be given.
  72. *
  73. * Whether the a stream supports color is usually automatically
  74. * detected, but with two exceptions:
  75. *
  76. * - When the stream is displayed in a terminal supporting VT100
  77. * color but using an intermediate pipe for communication the
  78. * detection of a tty fails. (This typically occurs for a shell
  79. * running in an rxvt terminal in MSYS.) If the caller knows this
  80. * to be the case, the attribute Color_AssumeTTY may be included in
  81. * the color specification.
  82. *
  83. * - When the stream is displayed in a terminal whose TERM
  84. * environment variable is not set or is set to a value that is not
  85. * known to support VT100 colors. If the caller knows this to be
  86. * the case, the attribute Color_AssumeVT100 may be included in the
  87. * color specification.
  88. */
  89. kwsysEXPORT void kwsysTerminal_cfprintf(int color, FILE* stream,
  90. const char* format, ...);
  91. enum kwsysTerminal_Color_e
  92. {
  93. /* Normal Text */
  94. kwsysTerminal_Color_Normal = 0,
  95. /* Foreground Color */
  96. kwsysTerminal_Color_ForegroundBlack = 0x1,
  97. kwsysTerminal_Color_ForegroundRed = 0x2,
  98. kwsysTerminal_Color_ForegroundGreen = 0x3,
  99. kwsysTerminal_Color_ForegroundYellow = 0x4,
  100. kwsysTerminal_Color_ForegroundBlue = 0x5,
  101. kwsysTerminal_Color_ForegroundMagenta = 0x6,
  102. kwsysTerminal_Color_ForegroundCyan = 0x7,
  103. kwsysTerminal_Color_ForegroundWhite = 0x8,
  104. kwsysTerminal_Color_ForegroundMask = 0xF,
  105. /* Background Color */
  106. kwsysTerminal_Color_BackgroundBlack = 0x10,
  107. kwsysTerminal_Color_BackgroundRed = 0x20,
  108. kwsysTerminal_Color_BackgroundGreen = 0x30,
  109. kwsysTerminal_Color_BackgroundYellow = 0x40,
  110. kwsysTerminal_Color_BackgroundBlue = 0x50,
  111. kwsysTerminal_Color_BackgroundMagenta = 0x60,
  112. kwsysTerminal_Color_BackgroundCyan = 0x70,
  113. kwsysTerminal_Color_BackgroundWhite = 0x80,
  114. kwsysTerminal_Color_BackgroundMask = 0xF0,
  115. /* Attributes */
  116. kwsysTerminal_Color_ForegroundBold = 0x100,
  117. kwsysTerminal_Color_BackgroundBold = 0x200,
  118. kwsysTerminal_Color_AssumeTTY = 0x400,
  119. kwsysTerminal_Color_AssumeVT100 = 0x800,
  120. kwsysTerminal_Color_AttributeMask = 0xF00
  121. };
  122. #if defined(__cplusplus)
  123. } /* extern "C" */
  124. #endif
  125. /* If we are building a kwsys .c or .cxx file, let it use these macros.
  126. Otherwise, undefine them to keep the namespace clean. */
  127. #if !defined(KWSYS_NAMESPACE)
  128. #undef kwsys_ns
  129. #undef kwsysEXPORT
  130. #if !cmsys_NAME_IS_KWSYS
  131. #undef kwsysTerminal_cfprintf
  132. #undef kwsysTerminal_Color_e
  133. #undef kwsysTerminal_Color_Normal
  134. #undef kwsysTerminal_Color_ForegroundBlack
  135. #undef kwsysTerminal_Color_ForegroundRed
  136. #undef kwsysTerminal_Color_ForegroundGreen
  137. #undef kwsysTerminal_Color_ForegroundYellow
  138. #undef kwsysTerminal_Color_ForegroundBlue
  139. #undef kwsysTerminal_Color_ForegroundMagenta
  140. #undef kwsysTerminal_Color_ForegroundCyan
  141. #undef kwsysTerminal_Color_ForegroundWhite
  142. #undef kwsysTerminal_Color_ForegroundMask
  143. #undef kwsysTerminal_Color_BackgroundBlack
  144. #undef kwsysTerminal_Color_BackgroundRed
  145. #undef kwsysTerminal_Color_BackgroundGreen
  146. #undef kwsysTerminal_Color_BackgroundYellow
  147. #undef kwsysTerminal_Color_BackgroundBlue
  148. #undef kwsysTerminal_Color_BackgroundMagenta
  149. #undef kwsysTerminal_Color_BackgroundCyan
  150. #undef kwsysTerminal_Color_BackgroundWhite
  151. #undef kwsysTerminal_Color_BackgroundMask
  152. #undef kwsysTerminal_Color_ForegroundBold
  153. #undef kwsysTerminal_Color_BackgroundBold
  154. #undef kwsysTerminal_Color_AssumeTTY
  155. #undef kwsysTerminal_Color_AssumeVT100
  156. #undef kwsysTerminal_Color_AttributeMask
  157. #endif
  158. #endif
  159. #endif