win32console 1.0.8-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/Console-i386-mswin32.def +2 -0
  2. data/Console.cpp +1203 -0
  3. data/Console.rdoc +690 -0
  4. data/Console_ANSI.rdoc +302 -0
  5. data/HISTORY.txt +7 -0
  6. data/INSTALL.txt +18 -0
  7. data/README.txt +26 -0
  8. data/Rakefile +38 -0
  9. data/doc/classes/Win32.html +115 -0
  10. data/doc/classes/Win32/Console.html +650 -0
  11. data/doc/classes/Win32/Console.src/M000001.html +31 -0
  12. data/doc/classes/Win32/Console.src/M000002.html +23 -0
  13. data/doc/classes/Win32/Console.src/M000003.html +23 -0
  14. data/doc/classes/Win32/Console.src/M000004.html +27 -0
  15. data/doc/classes/Win32/Console.src/M000005.html +23 -0
  16. data/doc/classes/Win32/Console.src/M000006.html +28 -0
  17. data/doc/classes/Win32/Console.src/M000007.html +23 -0
  18. data/doc/classes/Win32/Console.src/M000008.html +24 -0
  19. data/doc/classes/Win32/Console.src/M000009.html +44 -0
  20. data/doc/classes/Win32/Console.src/M000010.html +23 -0
  21. data/doc/classes/Win32/Console.src/M000011.html +33 -0
  22. data/doc/classes/Win32/Console.src/M000012.html +26 -0
  23. data/doc/classes/Win32/Console.src/M000013.html +27 -0
  24. data/doc/classes/Win32/Console.src/M000014.html +28 -0
  25. data/doc/classes/Win32/Console.src/M000015.html +23 -0
  26. data/doc/classes/Win32/Console.src/M000016.html +23 -0
  27. data/doc/classes/Win32/Console.src/M000017.html +23 -0
  28. data/doc/classes/Win32/Console.src/M000018.html +29 -0
  29. data/doc/classes/Win32/Console.src/M000019.html +23 -0
  30. data/doc/classes/Win32/Console.src/M000020.html +23 -0
  31. data/doc/classes/Win32/Console.src/M000021.html +28 -0
  32. data/doc/classes/Win32/Console.src/M000022.html +23 -0
  33. data/doc/classes/Win32/Console.src/M000023.html +28 -0
  34. data/doc/classes/Win32/Console.src/M000024.html +35 -0
  35. data/doc/classes/Win32/Console.src/M000025.html +28 -0
  36. data/doc/classes/Win32/Console.src/M000026.html +28 -0
  37. data/doc/classes/Win32/Console.src/M000027.html +28 -0
  38. data/doc/classes/Win32/Console.src/M000028.html +31 -0
  39. data/doc/classes/Win32/Console.src/M000029.html +23 -0
  40. data/doc/classes/Win32/Console.src/M000030.html +23 -0
  41. data/doc/classes/Win32/Console.src/M000031.html +23 -0
  42. data/doc/classes/Win32/Console.src/M000032.html +27 -0
  43. data/doc/classes/Win32/Console.src/M000033.html +27 -0
  44. data/doc/classes/Win32/Console.src/M000034.html +25 -0
  45. data/doc/classes/Win32/Console/ANSI.html +103 -0
  46. data/doc/classes/Win32/Console/ANSI/IO.html +220 -0
  47. data/doc/classes/Win32/Console/ANSI/IO.src/M000035.html +32 -0
  48. data/doc/classes/Win32/Console/ANSI/IO.src/M000036.html +205 -0
  49. data/doc/classes/Win32/Console/ANSI/IO.src/M000037.html +40 -0
  50. data/doc/classes/Win32/Console/ANSI/IO.src/M000038.html +25 -0
  51. data/doc/classes/Win32/Console/API.html +758 -0
  52. data/doc/classes/Win32/Console/API.src/M000039.html +27 -0
  53. data/doc/classes/Win32/Console/API.src/M000040.html +27 -0
  54. data/doc/classes/Win32/Console/API.src/M000041.html +27 -0
  55. data/doc/classes/Win32/Console/API.src/M000042.html +32 -0
  56. data/doc/classes/Win32/Console/API.src/M000043.html +32 -0
  57. data/doc/classes/Win32/Console/API.src/M000044.html +28 -0
  58. data/doc/classes/Win32/Console/API.src/M000045.html +26 -0
  59. data/doc/classes/Win32/Console/API.src/M000046.html +26 -0
  60. data/doc/classes/Win32/Console/API.src/M000047.html +27 -0
  61. data/doc/classes/Win32/Console/API.src/M000048.html +30 -0
  62. data/doc/classes/Win32/Console/API.src/M000049.html +29 -0
  63. data/doc/classes/Win32/Console/API.src/M000050.html +27 -0
  64. data/doc/classes/Win32/Console/API.src/M000051.html +28 -0
  65. data/doc/classes/Win32/Console/API.src/M000052.html +30 -0
  66. data/doc/classes/Win32/Console/API.src/M000053.html +27 -0
  67. data/doc/classes/Win32/Console/API.src/M000054.html +29 -0
  68. data/doc/classes/Win32/Console/API.src/M000055.html +29 -0
  69. data/doc/classes/Win32/Console/API.src/M000056.html +28 -0
  70. data/doc/classes/Win32/Console/API.src/M000057.html +27 -0
  71. data/doc/classes/Win32/Console/API.src/M000058.html +47 -0
  72. data/doc/classes/Win32/Console/API.src/M000059.html +32 -0
  73. data/doc/classes/Win32/Console/API.src/M000060.html +47 -0
  74. data/doc/classes/Win32/Console/API.src/M000061.html +34 -0
  75. data/doc/classes/Win32/Console/API.src/M000062.html +32 -0
  76. data/doc/classes/Win32/Console/API.src/M000063.html +32 -0
  77. data/doc/classes/Win32/Console/API.src/M000064.html +35 -0
  78. data/doc/classes/Win32/Console/API.src/M000065.html +26 -0
  79. data/doc/classes/Win32/Console/API.src/M000066.html +27 -0
  80. data/doc/classes/Win32/Console/API.src/M000067.html +29 -0
  81. data/doc/classes/Win32/Console/API.src/M000068.html +27 -0
  82. data/doc/classes/Win32/Console/API.src/M000069.html +27 -0
  83. data/doc/classes/Win32/Console/API.src/M000070.html +28 -0
  84. data/doc/classes/Win32/Console/API.src/M000071.html +27 -0
  85. data/doc/classes/Win32/Console/API.src/M000072.html +26 -0
  86. data/doc/classes/Win32/Console/API.src/M000073.html +27 -0
  87. data/doc/classes/Win32/Console/API.src/M000074.html +31 -0
  88. data/doc/classes/Win32/Console/API.src/M000075.html +27 -0
  89. data/doc/classes/Win32/Console/API.src/M000076.html +32 -0
  90. data/doc/classes/Win32/Console/API.src/M000077.html +27 -0
  91. data/doc/classes/Win32/Console/API.src/M000078.html +32 -0
  92. data/doc/classes/Win32/Console/API.src/M000079.html +32 -0
  93. data/doc/classes/Win32/Console/API.src/M000080.html +32 -0
  94. data/doc/classes/Win32/Console/Constants.html +360 -0
  95. data/doc/created.rid +1 -0
  96. data/doc/files/Console_ANSI_rdoc.html +407 -0
  97. data/doc/files/Console_cpp.html +104 -0
  98. data/doc/files/Console_rdoc.html +964 -0
  99. data/doc/files/lib/Win32/Console/ANSI_rb.html +123 -0
  100. data/doc/files/lib/Win32/Console_rb.html +297 -0
  101. data/doc/fr_class_index.html +32 -0
  102. data/doc/fr_file_index.html +31 -0
  103. data/doc/fr_method_index.html +106 -0
  104. data/doc/index.html +24 -0
  105. data/doc/rdoc-style.css +172 -0
  106. data/lib/Console.so +0 -0
  107. data/lib/README_GEM.txt +64 -0
  108. data/lib/Term/ansicolor.rb +76 -0
  109. data/lib/Win32/Console.rb +970 -0
  110. data/lib/Win32/Console/ANSI.rb +305 -0
  111. data/lib/win32console.rb +3 -0
  112. data/test/test_cursor.rb +9 -0
  113. data/test/test_mouse.rb +6 -0
  114. data/test/test_readinput.rb +62 -0
  115. data/test/test_readoutput.rb +52 -0
  116. data/test/test_sendevent.rb +17 -0
  117. data/test/test_title.rb +14 -0
  118. data/test/test_write.rb +36 -0
  119. metadata +180 -0
@@ -0,0 +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
+
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'Win32/Console/ANSI'
3
+ require 'Term/ansicolor'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+
6
+ a = Win32::Console.new(STD_OUTPUT_HANDLE)
7
+
8
+ puts "Setting cursor to visible and 100% fat"
9
+ a.Cursor(-1,-1,100,1)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ a = Win32::Console.new()
6
+ puts "# of Mouse buttons: #{Win32::Console.MouseButtons}"
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ include Win32::Console::Constants
6
+ a = Win32::Console.new(STD_INPUT_HANDLE)
7
+
8
+ puts "InputChar: Type a phrase then ENTER, please:"
9
+
10
+ x1 = a.InputChar(1)
11
+ puts "Your phrase starts with the character #{x1}"
12
+
13
+
14
+ fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT
15
+
16
+ a.Mode(fdwMode)
17
+
18
+ puts
19
+ puts "PeekInput: Type a character without ENTER or do something, please:"
20
+
21
+ while (x1 = a.PeekInput()).size < 1
22
+ end
23
+
24
+ if x1[0] == KEY_EVENT
25
+ puts "You typed #{x1[5]}='#{x1[5].chr}'"
26
+ else
27
+ print "You did not typed, but "
28
+ case x1[0]
29
+ when MOUSE_EVENT
30
+ puts "used mouse"
31
+ when WINDOW_BUFFER_SIZE_EVENT
32
+ puts "resize window"
33
+ when MENU_EVENT
34
+ puts "called menu"
35
+ when FOCUS_EVENT
36
+ puts "changed focus"
37
+ else
38
+ puts "...should never get here"
39
+ end
40
+ end
41
+
42
+ puts
43
+ puts "Input (as PeekInput keeps event, this reuses PeekInput value):"
44
+ x1 = a.Input()
45
+ if x1[0] == KEY_EVENT
46
+ puts "You typed #{x1[5]}='#{x1[5].chr}'"
47
+ else
48
+ print "You did not typed, but "
49
+ case x1[0]
50
+ when MOUSE_EVENT
51
+ puts "used mouse"
52
+ when WINDOW_BUFFER_SIZE_EVENT
53
+ puts "resize window"
54
+ when MENU_EVENT
55
+ puts "called menu"
56
+ when FOCUS_EVENT
57
+ puts "changed focus"
58
+ else
59
+ puts "...should never get here"
60
+ end
61
+ end
62
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ include Win32::Console::Constants
6
+ a = Win32::Console.new(STD_OUTPUT_HANDLE)
7
+
8
+ puts <<'EOF'
9
+ This is a simple
10
+ test of test to grab
11
+ from the console.
12
+ Hopefully this will work
13
+ easily and merrily.
14
+ This is a simple
15
+ test of test to grab
16
+ from the console.
17
+ Hopefully this will work
18
+ easily and merrily.
19
+ This is a simple
20
+ test of test to grab
21
+ from the console.
22
+ Hopefully this will work
23
+ easily and merrily.
24
+ EOF
25
+
26
+ x1 = a.ReadChar(10,10,10)
27
+ x2 = a.ReadAttr(10,10,10)
28
+ x3 = a.ReadRect(10,10,20,10)
29
+ puts "ReadChar .#{x1}."
30
+ puts x2.class, x2.size
31
+ print "ReadAttr ."
32
+ for i in x2
33
+ print "#{i}|"
34
+ end
35
+ print "\nReadRect ."
36
+
37
+ i = 0
38
+ while i < x3.length-1
39
+ print "#{x3[i]}"
40
+ i += 2
41
+ end
42
+ print "\n "
43
+ i = 1
44
+ while i < x3.length-1
45
+ print "#{x3[i]}|"
46
+ i += 2
47
+ end
48
+ print "\n"
49
+
50
+ #puts "read=",x1
51
+ #print "Attributes:",x2
52
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+
6
+ i = 0
7
+ begin
8
+ while i < 99
9
+ if i == 10
10
+ Win32::Console::GenerateCtrlEvent()
11
+ end
12
+ i = i.next
13
+ end
14
+ rescue Exception
15
+ end
16
+
17
+ puts "if i=10, then OK! i=#{i}"