PageRenderTime 44ms CodeModel.GetById 41ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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