stella 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/README.textile +14 -10
  2. data/Rakefile +22 -36
  3. data/lib/daemonize.rb +56 -0
  4. data/lib/stella/adapter/ab.rb +49 -39
  5. data/lib/stella/adapter/base.rb +17 -8
  6. data/lib/stella/adapter/httperf.rb +24 -18
  7. data/lib/stella/adapter/pcap_watcher.rb +1 -1
  8. data/lib/stella/adapter/siege.rb +15 -12
  9. data/lib/stella/cli/localtest.rb +2 -3
  10. data/lib/stella/cli/sysinfo.rb +0 -1
  11. data/lib/stella/cli.rb +10 -55
  12. data/lib/stella/command/base.rb +0 -62
  13. data/lib/stella/command/localtest.rb +35 -36
  14. data/lib/stella/data/domain.rb +18 -11
  15. data/lib/stella/data/http.rb +23 -16
  16. data/lib/stella/logger.rb +29 -19
  17. data/lib/stella/response.rb +5 -2
  18. data/lib/stella/storable.rb +138 -52
  19. data/lib/stella/support.rb +107 -8
  20. data/lib/stella/sysinfo.rb +26 -16
  21. data/lib/stella/test/definition.rb +1 -1
  22. data/lib/stella/test/run/summary.rb +23 -13
  23. data/lib/stella/test/stats.rb +114 -0
  24. data/lib/stella/text/resource.rb +1 -1
  25. data/lib/stella.rb +29 -4
  26. data/lib/utils/mathutil.rb +0 -76
  27. data/lib/utils/stats.rb +88 -0
  28. data/lib/win32/Console/ANSI.rb +305 -305
  29. data/lib/win32/Console.rb +970 -970
  30. data/support/ruby-pcap-takuma-patch.txt +13 -13
  31. data/support/text/en.yaml +11 -8
  32. data/support/text/nl.yaml +7 -1
  33. data/{spec/show-agents_spec.rb → tests/01-util_test.rb} +0 -0
  34. data/tests/02-stella-util_test.rb +42 -0
  35. data/tests/10-stella_test.rb +104 -0
  36. data/tests/11-stella-storable_test.rb +68 -0
  37. data/tests/60-stella-command_test.rb +248 -0
  38. data/tests/80-stella-cli_test.rb +45 -0
  39. data/tests/spec-helper.rb +31 -0
  40. data/vendor/{frylock/README.textile → drydock/LICENSE.txt} +2 -52
  41. data/vendor/drydock/README.textile +57 -0
  42. data/vendor/{frylock → drydock}/bin/example +14 -14
  43. data/vendor/{frylock/frylock.gemspec → drydock/drydock.gemspec} +1 -1
  44. data/vendor/{frylock/lib/frylock → drydock/lib/drydock}/exceptions.rb +1 -1
  45. data/vendor/{frylock/lib/frylock.rb → drydock/lib/drydock.rb} +8 -8
  46. data/vendor/{frylock → drydock}/test/command_test.rb +0 -0
  47. metadata +34 -61
  48. data/lib/stella/test/base.rb +0 -38
  49. data/lib/stella/test/summary.rb +0 -82
  50. data/vendor/hitimes-0.4.0/HISTORY +0 -28
  51. data/vendor/hitimes-0.4.0/LICENSE.txt +0 -19
  52. data/vendor/hitimes-0.4.0/README +0 -80
  53. data/vendor/hitimes-0.4.0/Rakefile +0 -63
  54. data/vendor/hitimes-0.4.0/examples/benchmarks.rb +0 -86
  55. data/vendor/hitimes-0.4.0/examples/stats.rb +0 -29
  56. data/vendor/hitimes-0.4.0/ext/extconf.rb +0 -15
  57. data/vendor/hitimes-0.4.0/ext/hitimes_ext.c +0 -21
  58. data/vendor/hitimes-0.4.0/ext/hitimes_instant_clock_gettime.c +0 -20
  59. data/vendor/hitimes-0.4.0/ext/hitimes_instant_osx.c +0 -16
  60. data/vendor/hitimes-0.4.0/ext/hitimes_instant_windows.c +0 -27
  61. data/vendor/hitimes-0.4.0/ext/hitimes_interval.c +0 -340
  62. data/vendor/hitimes-0.4.0/ext/hitimes_interval.h +0 -73
  63. data/vendor/hitimes-0.4.0/ext/hitimes_stats.c +0 -242
  64. data/vendor/hitimes-0.4.0/ext/hitimes_stats.h +0 -30
  65. data/vendor/hitimes-0.4.0/ext/rbconfig-mingw.rb +0 -178
  66. data/vendor/hitimes-0.4.0/ext/rbconfig.rb +0 -178
  67. data/vendor/hitimes-0.4.0/gemspec.rb +0 -54
  68. data/vendor/hitimes-0.4.0/lib/hitimes/mutexed_stats.rb +0 -23
  69. data/vendor/hitimes-0.4.0/lib/hitimes/paths.rb +0 -54
  70. data/vendor/hitimes-0.4.0/lib/hitimes/stats.rb +0 -29
  71. data/vendor/hitimes-0.4.0/lib/hitimes/timer.rb +0 -223
  72. data/vendor/hitimes-0.4.0/lib/hitimes/version.rb +0 -42
  73. data/vendor/hitimes-0.4.0/lib/hitimes.rb +0 -24
  74. data/vendor/hitimes-0.4.0/spec/interval_spec.rb +0 -115
  75. data/vendor/hitimes-0.4.0/spec/mutex_stats_spec.rb +0 -34
  76. data/vendor/hitimes-0.4.0/spec/paths_spec.rb +0 -14
  77. data/vendor/hitimes-0.4.0/spec/spec_helper.rb +0 -6
  78. data/vendor/hitimes-0.4.0/spec/stats_spec.rb +0 -72
  79. data/vendor/hitimes-0.4.0/spec/timer_spec.rb +0 -105
  80. data/vendor/hitimes-0.4.0/spec/version_spec.rb +0 -27
  81. data/vendor/hitimes-0.4.0/tasks/announce.rake +0 -39
  82. data/vendor/hitimes-0.4.0/tasks/config.rb +0 -107
  83. data/vendor/hitimes-0.4.0/tasks/distribution.rake +0 -53
  84. data/vendor/hitimes-0.4.0/tasks/documentation.rake +0 -33
  85. data/vendor/hitimes-0.4.0/tasks/extension.rake +0 -64
  86. data/vendor/hitimes-0.4.0/tasks/rspec.rake +0 -31
  87. data/vendor/hitimes-0.4.0/tasks/rubyforge.rake +0 -52
  88. data/vendor/hitimes-0.4.0/tasks/utils.rb +0 -80
@@ -1,305 +1,305 @@
1
- #
2
- # Win32::Console::ANSI
3
- #
4
- # Copyright 2004 - Gonzalo Garramuno
5
- # Licensed under GNU General Public License or Perl's Artistic License
6
- #
7
- # Based on Perl's Win32::Console::ANSI
8
- # Copyright (c) 2003 Jean-Louis Morel <jl_morel@bribes.org>
9
- # Licensed under GNU General Public License or Perl's Artistic License
10
- #
11
- require "win32/Console"
12
-
13
- module Win32
14
- class Console
15
- module ANSI
16
-
17
- class IO < IO
18
-
19
- VERSION = '0.05'
20
- DEBUG = nil
21
-
22
- require "win32/registry"
23
-
24
- include Win32::Console::Constants
25
-
26
- # @todo: encode is another perl module
27
- EncodeOk = false
28
-
29
- # Retrieving the codepages
30
- cpANSI = nil
31
- Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Nls\CodePage' ) { |reg|
32
- cpANSI = reg['ACP']
33
- }
34
-
35
- STDERR.puts "Unable to read Win codepage #{cpANSI}" if DEBUG && !cpANSI
36
-
37
-
38
- cpANSI = 'cp'+(cpANSI ? cpANSI : '1252') # Windows codepage
39
- OEM = Win32::Console::OutputCP()
40
- cpOEM = 'cp' + OEM.to_s # DOS codepage
41
- @@cp = cpANSI + cpOEM
42
-
43
- STDERR.puts "EncodeOk=#{EncodeOk} cpANSI=#{cpANSI} "+
44
- "cpOEM=#{cpOEM}" if DEBUG
45
-
46
- @@color = { 30 => 0, # black foreground
47
- 31 => FOREGROUND_RED, # red foreground
48
- 32 => FOREGROUND_GREEN, # green foreground
49
- 33 => FOREGROUND_RED|FOREGROUND_GREEN, # yellow foreground
50
- 34 => FOREGROUND_BLUE, # blue foreground
51
- 35 => FOREGROUND_BLUE|FOREGROUND_RED, # magenta foreground
52
- 36 => FOREGROUND_BLUE|FOREGROUND_GREEN, # cyan foreground
53
- 37 => FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE, # white foreground
54
- 40 => 0, # black background
55
- 41 => BACKGROUND_RED, # red background
56
- 42 => BACKGROUND_GREEN, # green background
57
- 43 => BACKGROUND_RED|BACKGROUND_GREEN, # yellow background
58
- 44 => BACKGROUND_BLUE, # blue background
59
- 45 => BACKGROUND_BLUE|BACKGROUND_RED, # magenta background
60
- 46 => BACKGROUND_BLUE|BACKGROUND_GREEN, # cyan background
61
- 47 => BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE, # white background
62
- }
63
-
64
- def initialize
65
- super(1,'w')
66
- @Out = Win32::Console.new(STD_OUTPUT_HANDLE)
67
- @x = @y = 0 # to save cursor position
68
- @foreground = 7
69
- @background = 0
70
- @bold =
71
- @underline =
72
- @revideo =
73
- @concealed = nil
74
- @conv = 1 # char conversion by default
75
- end
76
-
77
-
78
- def write(*s)
79
- s.each { |x|
80
- _PrintString(x)
81
- }
82
- end
83
-
84
-
85
- private
86
-
87
- def _PrintString(t)
88
- s = t.dup
89
- while s != ''
90
- if s.sub!( /([^\e]*)?\e([\[\(])([0-9\;\=]*)([a-zA-Z@])(.*)/s,'\5')
91
- @Out.Write((_conv("#$1")))
92
- if $2 == '['
93
- case $4
94
- when 'm' # ESC[#;#;....;#m Set display attributes
95
- attributs = $3.split(';')
96
- attributs.push(nil) unless attributs # ESC[m == ESC[;m ==...==ESC[0m
97
- for attr in attributs
98
- atv = attr.to_i
99
- if atv > 0
100
- if atv == 1
101
- @bold = 1
102
- elsif atv == 21
103
- @bold = nil
104
- elsif atv == 4
105
- @underline = 1
106
- elsif atv == 24
107
- @underline = nil
108
- elsif atv == 7
109
- @revideo = 1
110
- elsif atv == 27
111
- @revideo = nil
112
- elsif atv == 8
113
- @concealed = 1
114
- elsif atv == 28
115
- @concealed = nil
116
- elsif atv >= 30 and atv <= 37
117
- @foreground = atv - 30
118
- elsif atv >=40 and atv <=47
119
- @background = atv - 40
120
- end
121
- else # ESC[0m reset
122
- @foreground = 7
123
- @background = 0
124
- @bold =
125
- @underline =
126
- @revideo =
127
- @concealed = nil
128
- end
129
- end
130
-
131
- if @revideo
132
- attribut = @@color[40+@foreground] |
133
- @@color[30+@background]
134
- else
135
- attribut = @@color[30+@foreground] |
136
- @@color[40+@background]
137
- end
138
- attribut |= FOREGROUND_INTENSITY if @bold
139
- attribut |= BACKGROUND_INTENSITY if @underline
140
- @Out.Attr(attribut)
141
- when 'J'
142
- if !$3 or $3 == '' # ESC[0J from cursor to end of display
143
- info = @Out.Info()
144
- s = ' ' * ((info[1]-info[3]-1)*info[0]+info[0]-info[2]-1)
145
- @Out.WriteChar(s, info[2], info[3])
146
- @Out.Cursor(info[2], info[3])
147
- elsif $3 == '1' # ESC[1J erase from start to cursor.
148
- info = @Out.Info()
149
- s = ' ' * (info[3]*info[0]+info[2]+1)
150
- @Out.WriteChar(s, 0, 0)
151
- @Out.Cursor(info[2], info[3])
152
- elsif $3 == '2' # ESC[2J Clear screen and home cursor
153
- @Out.Cls()
154
- @Out.Cursor(0, 0)
155
- else
156
- STDERR.print "\e#$2#$3#$4" if DEBUG # if ESC-code not implemented
157
- end
158
- when 'K'
159
- info = @Out.Info()
160
- if !$3 or $3 == '' # ESC[0K Clear to end of line
161
- s = ' ' * (info[7]-info[2]+1)
162
- @Out.Write(s)
163
- @Out.Cursor(info[2], info[3])
164
- elsif $3=='1' # ESC[1K Clear from start of line to cursor
165
- s = ' '*(info[2]+1)
166
- @Out.WriteChar(s, 0, info[3])
167
- @Out.Cursor(info[2], info[3])
168
- elsif $3=='2' # ESC[2K Clear whole line.
169
- s = ' '* info[0]
170
- @Out.WriteChar(s, 0, info[3])
171
- @Out.Cursor(info[2], info[3])
172
- end
173
- when 'L' # ESC[#L Insert # blank lines.
174
- n = $3 == ''? 1 : $3.to_i # ESC[L == ESC[1L
175
- info = @Out.Info()
176
- @Out.Scroll(0, info[3], info[0]-1, info[1]-1,
177
- 0, info[3] + n.to_i,
178
- ' '[0], @Out.Attr(),
179
- 0, 0, 10000, 10000)
180
- @Out.Cursor(info[2], info[3])
181
- when 'M' # ESC[#M Delete # line.
182
- n = $3 == ''? 1 : $3.to_i # ESC[M == ESC[1M
183
- info = @Out.Info();
184
- @Out.Scroll(0, info[3]+n, info[0]-1, info[1]-1,
185
- 0, info[3],
186
- ' '[0], @Out.Attr(),
187
- 0, 0, 10000, 10000)
188
- @Out.Cursor(info[2], info[3])
189
- when 'P' # ESC[#P Delete # characters.
190
- n = $3 == ''? 1 : $3.to_i # ESC[P == ESC[1P
191
- info = @Out.Info()
192
- n = info[0]-info[2] if info[2]+n > info[0]-1
193
- @Out.Scroll(info[2]+n, info[3] , info[0]-1, info[3],
194
- info[2], info[3],
195
- ' '[0], @Out.Attr(),
196
- 0, 0, 10000, 10000)
197
- s = ' ' * n
198
- @Out.Cursor(info[0]-n, info[3])
199
- @Out.Write(s)
200
- @Out.Cursor(info[2], info[3])
201
- when '@' # ESC[#@ Insert # blank Characters
202
- s = ' ' * $3.to_i
203
- info = @Out.Info()
204
- s << @Out.ReadChar(info[7]-info[2]+1, info[2], info[3])
205
- s = s[0..-($3.to_i)]
206
- @Out.Write(s);
207
- @Out.Cursor(info[2], info[3])
208
- when 'A' # ESC[#A Moves cursor up # lines
209
- (x, y) = @Out.Cursor()
210
- n = $3 == ''? 1 : $3.to_i; # ESC[A == ESC[1A
211
- @Out.Cursor(x, y-n)
212
- when 'B' # ESC[#B Moves cursor down # lines
213
- (x, y) = @Out.Cursor()
214
- n = $3 == ''? 1 : $3.to_i; # ESC[B == ESC[1B
215
- @Out.Cursor(x, y+n)
216
- when 'C' # ESC[#C Moves cursor forward # spaces
217
- (x, y) = @Out.Cursor()
218
- n = $3 == ''? 1 : $3.to_i; # ESC[C == ESC[1C
219
- @Out.Cursor(x+n, y)
220
- when 'D' # ESC[#D Moves cursor back # spaces
221
- (x, y) = @Out.Cursor()
222
- n = $3 == ''? 1 : $3.to_i; # ESC[D == ESC[1D
223
- @Out.Cursor(x-n, y)
224
- when 'E' # ESC[#E Moves cursor down # lines, column 1.
225
- x, y = @Out.Cursor()
226
- n = $3 == ''? 1 : $3.to_i; # ESC[E == ESC[1E
227
- @Out.Cursor(0, y+n)
228
- when 'F' # ESC[#F Moves cursor up # lines, column 1.
229
- x, y = @Out.Cursor()
230
- n = $3 == ''? 1 : $3.to_i; # ESC[F == ESC[1F
231
- @Out.Cursor(0, y-n)
232
- when 'G' # ESC[#G Moves cursor column # in current row.
233
- x, y = @Out.Cursor()
234
- n = $3 == ''? 1 : $3.to_i; # ESC[G == ESC[1G
235
- @Out.Cursor(n-1, y)
236
- when 'f' # ESC[#;#f Moves cursor to line #, column #
237
- y, x = $3.split(';')
238
- x = 1 unless x # ESC[;5H == ESC[1;5H ...etc
239
- y = 1 unless y
240
- @Out.Cursor(x.to_i-1, y.to_i-1) # origin (0,0) in DOS console
241
- when 'H' # ESC[#;#H Moves cursor to line #, column #
242
- y, x = $3.split(';')
243
- x = 1 unless x # ESC[;5H == ESC[1;5H ...etc
244
- y = 1 unless y
245
- @Out.Cursor(x.to_i-1, y.to_i-1) # origin (0,0) in DOS console
246
- when 's' # ESC[s Saves cursor position for recall later
247
- (@x, @y) = @Out.Cursor()
248
- when 'u' # ESC[u Return to saved cursor position
249
- @Out.Cursor(@x, @y)
250
- else
251
- STDERR.puts "\e#$2#$3#$4 not implemented" if DEBUG # ESC-code not implemented
252
- end
253
- else
254
- case $4
255
- when 'U' # ESC(U no mapping
256
- @conv = nil
257
- when 'K' # ESC(K mapping if it exist
258
- @Out.OutputCP(OEM) # restore original codepage
259
- @conv = 1
260
- when 'X' # ESC(#X codepage **EXPERIMENTAL**
261
- @conv = nil
262
- @Out.OutputCP($3)
263
- else
264
- STDERR.puts "\e#$2#$3#$4 not implemented" if DEBUG # ESC-code not implemented
265
- end
266
- end
267
- else
268
- @Out.Write(_conv(s))
269
- s=''
270
- end
271
- end
272
- end
273
-
274
- def _conv(s)
275
- if @concealed
276
- s.gsub!( /\S/,' ')
277
- elsif @conv
278
- if EncodeOk
279
- from_to(s, cpANSI, cpOEM)
280
- elsif @@cp == 'cp1252cp850' # WinLatin1 --> DOSLatin1
281
- s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������","???�??????????????????????????��������ρ��݁�����������������������������������������󁨁������ǎ����Ԑ�ҁӁށցׁ؁с������噞����ꚁ��ᅁ���Ƅ�������������Ё������䔁����������")
282
- elsif @@cp == 'cp1252cp437' # WinLatin1 --> DOSLatinUS
283
- s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������", "??????????????????????????????������?�????������???�����??��?��??��������?��????����?�???????��????�?????�??�ᅁ��?�������������?������?���?�����??�")
284
- elsif @@cp == 'cp1250cp852' # WinLatin2 --> DOSLatin2
285
- s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������",
286
- "??????????��?��??????????��?������������ρ�?����?��������?����?���???����������񖁾�聵���Ǝ���������Ӂ��ցׁҁс�Ձ��⊙����ށ�뚁�݁�ꁠ��DŽ���������؁���ԁЁ�偢�����������������" )
287
- elsif @@cp == 'cp1251cp855' # WinCyrillic --> DOSCyrillic
288
- s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������",
289
- "��?�??????�?����?????????�?����������??���?���?��?�??��????������������쁭������􁸁��ǁсӁՁׁ݁���聫�����������������������끬������󁷁��ƁЁҁԁց؁���灪������������������")
290
- end
291
- end
292
- return s
293
- end
294
-
295
- end
296
-
297
- # end print overloading
298
-
299
- end
300
- end
301
- end
302
-
303
-
304
- $stdout = Win32::Console::ANSI::IO.new()
305
-
1
+ #
2
+ # Win32::Console::ANSI
3
+ #
4
+ # Copyright 2004 - Gonzalo Garramuno
5
+ # Licensed under GNU General Public License or Perl's Artistic License
6
+ #
7
+ # Based on Perl's Win32::Console::ANSI
8
+ # Copyright (c) 2003 Jean-Louis Morel <jl_morel@bribes.org>
9
+ # Licensed under GNU General Public License or Perl's Artistic License
10
+ #
11
+ require "win32/Console"
12
+
13
+ module Win32
14
+ class Console
15
+ module ANSI
16
+
17
+ class IO < IO
18
+
19
+ VERSION = '0.05'
20
+ DEBUG = nil
21
+
22
+ require "win32/registry"
23
+
24
+ include Win32::Console::Constants
25
+
26
+ # @todo: encode is another perl module
27
+ EncodeOk = false
28
+
29
+ # Retrieving the codepages
30
+ cpANSI = nil
31
+ Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Nls\CodePage' ) { |reg|
32
+ cpANSI = reg['ACP']
33
+ }
34
+
35
+ STDERR.puts "Unable to read Win codepage #{cpANSI}" if DEBUG && !cpANSI
36
+
37
+
38
+ cpANSI = 'cp'+(cpANSI ? cpANSI : '1252') # Windows codepage
39
+ OEM = Win32::Console::OutputCP()
40
+ cpOEM = 'cp' + OEM.to_s # DOS codepage
41
+ @@cp = cpANSI + cpOEM
42
+
43
+ STDERR.puts "EncodeOk=#{EncodeOk} cpANSI=#{cpANSI} "+
44
+ "cpOEM=#{cpOEM}" if DEBUG
45
+
46
+ @@color = { 30 => 0, # black foreground
47
+ 31 => FOREGROUND_RED, # red foreground
48
+ 32 => FOREGROUND_GREEN, # green foreground
49
+ 33 => FOREGROUND_RED|FOREGROUND_GREEN, # yellow foreground
50
+ 34 => FOREGROUND_BLUE, # blue foreground
51
+ 35 => FOREGROUND_BLUE|FOREGROUND_RED, # magenta foreground
52
+ 36 => FOREGROUND_BLUE|FOREGROUND_GREEN, # cyan foreground
53
+ 37 => FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE, # white foreground
54
+ 40 => 0, # black background
55
+ 41 => BACKGROUND_RED, # red background
56
+ 42 => BACKGROUND_GREEN, # green background
57
+ 43 => BACKGROUND_RED|BACKGROUND_GREEN, # yellow background
58
+ 44 => BACKGROUND_BLUE, # blue background
59
+ 45 => BACKGROUND_BLUE|BACKGROUND_RED, # magenta background
60
+ 46 => BACKGROUND_BLUE|BACKGROUND_GREEN, # cyan background
61
+ 47 => BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE, # white background
62
+ }
63
+
64
+ def initialize
65
+ super(1,'w')
66
+ @Out = Win32::Console.new(STD_OUTPUT_HANDLE)
67
+ @x = @y = 0 # to save cursor position
68
+ @foreground = 7
69
+ @background = 0
70
+ @bold =
71
+ @underline =
72
+ @revideo =
73
+ @concealed = nil
74
+ @conv = 1 # char conversion by default
75
+ end
76
+
77
+
78
+ def write(*s)
79
+ s.each { |x|
80
+ _PrintString(x)
81
+ }
82
+ end
83
+
84
+
85
+ private
86
+
87
+ def _PrintString(t)
88
+ s = t.dup
89
+ while s != ''
90
+ if s.sub!( /([^\e]*)?\e([\[\(])([0-9\;\=]*)([a-zA-Z@])(.*)/s,'\5')
91
+ @Out.Write((_conv("#$1")))
92
+ if $2 == '['
93
+ case $4
94
+ when 'm' # ESC[#;#;....;#m Set display attributes
95
+ attributs = $3.split(';')
96
+ attributs.push(nil) unless attributs # ESC[m == ESC[;m ==...==ESC[0m
97
+ for attr in attributs
98
+ atv = attr.to_i
99
+ if atv > 0
100
+ if atv == 1
101
+ @bold = 1
102
+ elsif atv == 21
103
+ @bold = nil
104
+ elsif atv == 4
105
+ @underline = 1
106
+ elsif atv == 24
107
+ @underline = nil
108
+ elsif atv == 7
109
+ @revideo = 1
110
+ elsif atv == 27
111
+ @revideo = nil
112
+ elsif atv == 8
113
+ @concealed = 1
114
+ elsif atv == 28
115
+ @concealed = nil
116
+ elsif atv >= 30 and atv <= 37
117
+ @foreground = atv - 30
118
+ elsif atv >=40 and atv <=47
119
+ @background = atv - 40
120
+ end
121
+ else # ESC[0m reset
122
+ @foreground = 7
123
+ @background = 0
124
+ @bold =
125
+ @underline =
126
+ @revideo =
127
+ @concealed = nil
128
+ end
129
+ end
130
+
131
+ if @revideo
132
+ attribut = @@color[40+@foreground] |
133
+ @@color[30+@background]
134
+ else
135
+ attribut = @@color[30+@foreground] |
136
+ @@color[40+@background]
137
+ end
138
+ attribut |= FOREGROUND_INTENSITY if @bold
139
+ attribut |= BACKGROUND_INTENSITY if @underline
140
+ @Out.Attr(attribut)
141
+ when 'J'
142
+ if !$3 or $3 == '' # ESC[0J from cursor to end of display
143
+ info = @Out.Info()
144
+ s = ' ' * ((info[1]-info[3]-1)*info[0]+info[0]-info[2]-1)
145
+ @Out.WriteChar(s, info[2], info[3])
146
+ @Out.Cursor(info[2], info[3])
147
+ elsif $3 == '1' # ESC[1J erase from start to cursor.
148
+ info = @Out.Info()
149
+ s = ' ' * (info[3]*info[0]+info[2]+1)
150
+ @Out.WriteChar(s, 0, 0)
151
+ @Out.Cursor(info[2], info[3])
152
+ elsif $3 == '2' # ESC[2J Clear screen and home cursor
153
+ @Out.Cls()
154
+ @Out.Cursor(0, 0)
155
+ else
156
+ STDERR.print "\e#$2#$3#$4" if DEBUG # if ESC-code not implemented
157
+ end
158
+ when 'K'
159
+ info = @Out.Info()
160
+ if !$3 or $3 == '' # ESC[0K Clear to end of line
161
+ s = ' ' * (info[7]-info[2]+1)
162
+ @Out.Write(s)
163
+ @Out.Cursor(info[2], info[3])
164
+ elsif $3=='1' # ESC[1K Clear from start of line to cursor
165
+ s = ' '*(info[2]+1)
166
+ @Out.WriteChar(s, 0, info[3])
167
+ @Out.Cursor(info[2], info[3])
168
+ elsif $3=='2' # ESC[2K Clear whole line.
169
+ s = ' '* info[0]
170
+ @Out.WriteChar(s, 0, info[3])
171
+ @Out.Cursor(info[2], info[3])
172
+ end
173
+ when 'L' # ESC[#L Insert # blank lines.
174
+ n = $3 == ''? 1 : $3.to_i # ESC[L == ESC[1L
175
+ info = @Out.Info()
176
+ @Out.Scroll(0, info[3], info[0]-1, info[1]-1,
177
+ 0, info[3] + n.to_i,
178
+ ' '[0], @Out.Attr(),
179
+ 0, 0, 10000, 10000)
180
+ @Out.Cursor(info[2], info[3])
181
+ when 'M' # ESC[#M Delete # line.
182
+ n = $3 == ''? 1 : $3.to_i # ESC[M == ESC[1M
183
+ info = @Out.Info();
184
+ @Out.Scroll(0, info[3]+n, info[0]-1, info[1]-1,
185
+ 0, info[3],
186
+ ' '[0], @Out.Attr(),
187
+ 0, 0, 10000, 10000)
188
+ @Out.Cursor(info[2], info[3])
189
+ when 'P' # ESC[#P Delete # characters.
190
+ n = $3 == ''? 1 : $3.to_i # ESC[P == ESC[1P
191
+ info = @Out.Info()
192
+ n = info[0]-info[2] if info[2]+n > info[0]-1
193
+ @Out.Scroll(info[2]+n, info[3] , info[0]-1, info[3],
194
+ info[2], info[3],
195
+ ' '[0], @Out.Attr(),
196
+ 0, 0, 10000, 10000)
197
+ s = ' ' * n
198
+ @Out.Cursor(info[0]-n, info[3])
199
+ @Out.Write(s)
200
+ @Out.Cursor(info[2], info[3])
201
+ when '@' # ESC[#@ Insert # blank Characters
202
+ s = ' ' * $3.to_i
203
+ info = @Out.Info()
204
+ s << @Out.ReadChar(info[7]-info[2]+1, info[2], info[3])
205
+ s = s[0..-($3.to_i)]
206
+ @Out.Write(s);
207
+ @Out.Cursor(info[2], info[3])
208
+ when 'A' # ESC[#A Moves cursor up # lines
209
+ (x, y) = @Out.Cursor()
210
+ n = $3 == ''? 1 : $3.to_i; # ESC[A == ESC[1A
211
+ @Out.Cursor(x, y-n)
212
+ when 'B' # ESC[#B Moves cursor down # lines
213
+ (x, y) = @Out.Cursor()
214
+ n = $3 == ''? 1 : $3.to_i; # ESC[B == ESC[1B
215
+ @Out.Cursor(x, y+n)
216
+ when 'C' # ESC[#C Moves cursor forward # spaces
217
+ (x, y) = @Out.Cursor()
218
+ n = $3 == ''? 1 : $3.to_i; # ESC[C == ESC[1C
219
+ @Out.Cursor(x+n, y)
220
+ when 'D' # ESC[#D Moves cursor back # spaces
221
+ (x, y) = @Out.Cursor()
222
+ n = $3 == ''? 1 : $3.to_i; # ESC[D == ESC[1D
223
+ @Out.Cursor(x-n, y)
224
+ when 'E' # ESC[#E Moves cursor down # lines, column 1.
225
+ x, y = @Out.Cursor()
226
+ n = $3 == ''? 1 : $3.to_i; # ESC[E == ESC[1E
227
+ @Out.Cursor(0, y+n)
228
+ when 'F' # ESC[#F Moves cursor up # lines, column 1.
229
+ x, y = @Out.Cursor()
230
+ n = $3 == ''? 1 : $3.to_i; # ESC[F == ESC[1F
231
+ @Out.Cursor(0, y-n)
232
+ when 'G' # ESC[#G Moves cursor column # in current row.
233
+ x, y = @Out.Cursor()
234
+ n = $3 == ''? 1 : $3.to_i; # ESC[G == ESC[1G
235
+ @Out.Cursor(n-1, y)
236
+ when 'f' # ESC[#;#f Moves cursor to line #, column #
237
+ y, x = $3.split(';')
238
+ x = 1 unless x # ESC[;5H == ESC[1;5H ...etc
239
+ y = 1 unless y
240
+ @Out.Cursor(x.to_i-1, y.to_i-1) # origin (0,0) in DOS console
241
+ when 'H' # ESC[#;#H Moves cursor to line #, column #
242
+ y, x = $3.split(';')
243
+ x = 1 unless x # ESC[;5H == ESC[1;5H ...etc
244
+ y = 1 unless y
245
+ @Out.Cursor(x.to_i-1, y.to_i-1) # origin (0,0) in DOS console
246
+ when 's' # ESC[s Saves cursor position for recall later
247
+ (@x, @y) = @Out.Cursor()
248
+ when 'u' # ESC[u Return to saved cursor position
249
+ @Out.Cursor(@x, @y)
250
+ else
251
+ STDERR.puts "\e#$2#$3#$4 not implemented" if DEBUG # ESC-code not implemented
252
+ end
253
+ else
254
+ case $4
255
+ when 'U' # ESC(U no mapping
256
+ @conv = nil
257
+ when 'K' # ESC(K mapping if it exist
258
+ @Out.OutputCP(OEM) # restore original codepage
259
+ @conv = 1
260
+ when 'X' # ESC(#X codepage **EXPERIMENTAL**
261
+ @conv = nil
262
+ @Out.OutputCP($3)
263
+ else
264
+ STDERR.puts "\e#$2#$3#$4 not implemented" if DEBUG # ESC-code not implemented
265
+ end
266
+ end
267
+ else
268
+ @Out.Write(_conv(s))
269
+ s=''
270
+ end
271
+ end
272
+ end
273
+
274
+ def _conv(s)
275
+ if @concealed
276
+ s.gsub!( /\S/,' ')
277
+ elsif @conv
278
+ if EncodeOk
279
+ from_to(s, cpANSI, cpOEM)
280
+ elsif @@cp == 'cp1252cp850' # WinLatin1 --> DOSLatin1
281
+ s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������","???�??????????????????????????��������ρ��݁�����������������������������������������󁨁������ǎ����Ԑ�ҁӁށցׁ؁с������噞����ꚁ��ᅁ���Ƅ�������������Ё������䔁����������")
282
+ elsif @@cp == 'cp1252cp437' # WinLatin1 --> DOSLatinUS
283
+ s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������", "??????????????????????????????������?�????������???�����??��?��??��������?��????����?�???????��????�?????�??�ᅁ��?�������������?������?���?�����??�")
284
+ elsif @@cp == 'cp1250cp852' # WinLatin2 --> DOSLatin2
285
+ s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������",
286
+ "??????????��?��??????????��?������������ρ�?����?��������?����?���???����������񖁾�聵���Ǝ���������Ӂ��ցׁҁс�Ձ��⊙����ށ�뚁�݁�ꁠ��DŽ���������؁���ԁЁ�偢�����������������" )
287
+ elsif @@cp == 'cp1251cp855' # WinCyrillic --> DOSCyrillic
288
+ s.tr!("���������������������������������������������������������������������������������������������������ÁāŁƁǁȁɁʁˁ́́΁ρЁсҁӁԁՁցׁ؁فځہ܁݁ށ߁��������������������������������������������",
289
+ "��?�??????�?����?????????�?����������??���?���?��?�??��????������������쁭������􁸁��ǁсӁՁׁ݁���聫�����������������������끬������󁷁��ƁЁҁԁց؁���灪������������������")
290
+ end
291
+ end
292
+ return s
293
+ end
294
+
295
+ end
296
+
297
+ # end print overloading
298
+
299
+ end
300
+ end
301
+ end
302
+
303
+
304
+ $stdout = Win32::Console::ANSI::IO.new()
305
+