/src/lib/io/filter/ansi_output_stream.e

http://github.com/tybor/Liberty · Specman e · 184 lines · 136 code · 22 blank · 26 comment · 7 complexity · feb687bd6f6034f14b5b648eb9633d1d MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class ANSI_OUTPUT_STREAM
  5. --
  6. -- An ANSI-aware encoder.
  7. --
  8. inherit
  9. FILTER_OUTPUT_STREAM
  10. create {ANY}
  11. connect_to
  12. feature{ANY}
  13. set_foreground (color: INTEGER)
  14. require
  15. color.in_range(0, 7) or else color = 9
  16. do
  17. put_color_sequence(30 + color)
  18. end
  19. set_background (color: INTEGER)
  20. require
  21. color.in_range(0, 7) or else color = 9
  22. do
  23. put_color_sequence(40 + color)
  24. end
  25. reset
  26. do
  27. put_sequence(0)
  28. is_bold := False
  29. is_italic := False
  30. is_underline := False
  31. is_inverse := False
  32. is_strikethrough := False
  33. ensure
  34. not is_bold
  35. not is_italic
  36. not is_underline
  37. not is_inverse
  38. not is_strikethrough
  39. end
  40. set_bold (bold: BOOLEAN)
  41. require
  42. bold = not is_bold
  43. do
  44. is_bold := bold
  45. ensure
  46. is_bold = old bold
  47. end
  48. is_bold: BOOLEAN
  49. set_italic (italic: BOOLEAN)
  50. require
  51. italic = not is_italic
  52. do
  53. is_italic := italic
  54. ensure
  55. is_italic = old italic
  56. end
  57. is_italic: BOOLEAN
  58. set_underline (underline: BOOLEAN)
  59. require
  60. underline = not is_underline
  61. do
  62. is_underline := underline
  63. ensure
  64. is_underline = old underline
  65. end
  66. is_underline: BOOLEAN
  67. set_inverse (inverse: BOOLEAN)
  68. require
  69. inverse = not is_inverse
  70. do
  71. is_inverse := inverse
  72. ensure
  73. is_inverse = inverse
  74. end
  75. is_inverse: BOOLEAN
  76. set_strikethrough (strike: BOOLEAN)
  77. require
  78. strike = not is_strikethrough
  79. do
  80. is_strikethrough := strike
  81. ensure
  82. is_strikethrough = old strike
  83. end
  84. is_strikethrough: BOOLEAN
  85. black: INTEGER 0
  86. red: INTEGER 1
  87. green: INTEGER 2
  88. yellow: INTEGER 3
  89. blue: INTEGER 4
  90. magenta: INTEGER 5
  91. cyan: INTEGER 6
  92. white: INTEGER 7
  93. default_color: INTEGER 9
  94. feature {}
  95. local_can_disconnect: BOOLEAN True
  96. put_color_sequence (seq: INTEGER)
  97. do
  98. put_string("%/27/[0;")
  99. put_integer(seq)
  100. put_character('m')
  101. if is_bold then
  102. put_sequence(1)
  103. else
  104. put_sequence(22)
  105. end
  106. if is_italic then
  107. put_sequence(3)
  108. else
  109. put_sequence(23)
  110. end
  111. if is_underline then
  112. put_sequence(4)
  113. else
  114. put_sequence(24)
  115. end
  116. if is_inverse then
  117. put_sequence(7)
  118. else
  119. put_sequence(27)
  120. end
  121. if is_strikethrough then
  122. put_sequence(9)
  123. else
  124. put_sequence(29)
  125. end
  126. end
  127. put_sequence (seq: INTEGER)
  128. do
  129. put_string("%/27/[")
  130. put_integer(seq)
  131. put_character('m')
  132. end
  133. feature {FILTER_OUTPUT_STREAM}
  134. filtered_put_character (c: CHARACTER)
  135. do
  136. stream.filtered_put_character(c)
  137. end
  138. filtered_flush
  139. do
  140. stream.filtered_flush
  141. end
  142. end -- class ANSI_OUTPUT_STREAM
  143. --
  144. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  145. --
  146. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  147. -- of this software and associated documentation files (the "Software"), to deal
  148. -- in the Software without restriction, including without limitation the rights
  149. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  150. -- copies of the Software, and to permit persons to whom the Software is
  151. -- furnished to do so, subject to the following conditions:
  152. --
  153. -- The above copyright notice and this permission notice shall be included in
  154. -- all copies or substantial portions of the Software.
  155. --
  156. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  157. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  158. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  159. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  160. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  161. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  162. -- THE SOFTWARE.