win32console 1.2.0-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.txt +7 -0
- data/HISTORY_GEM.txt +38 -0
- data/INSTALL.txt +18 -0
- data/README.txt +25 -0
- data/README_GEM.txt +64 -0
- data/Rakefile +49 -0
- data/doc/Console.rdoc +690 -0
- data/doc/Console_ANSI.rdoc +302 -0
- data/ext/Console.cpp +1218 -0
- data/ext/extconf.rb +18 -0
- data/lib/Console.so +0 -0
- data/lib/Win32/Console/ANSI.rb +348 -0
- data/lib/Win32/Console/api.rb +342 -0
- data/lib/Win32/Console/constants.rb +66 -0
- data/lib/Win32/Console.rb +372 -0
- data/lib/win32console.rb +1 -0
- data/test/test_cursor.rb +9 -0
- data/test/test_mouse.rb +6 -0
- data/test/test_readinput.rb +62 -0
- data/test/test_readoutput.rb +52 -0
- data/test/test_sendevent.rb +17 -0
- data/test/test_title.rb +14 -0
- data/test/test_write.rb +36 -0
- metadata +83 -0
@@ -0,0 +1,372 @@
|
|
1
|
+
# Win32::Console: an object implementing the Win32 API Console functions
|
2
|
+
# Copyright (C) 2003 Gonzalo Garramuno (ggarramuno@aol.com)
|
3
|
+
#
|
4
|
+
# Original Win32API_Console was:
|
5
|
+
# Copyright (C) 2001 Michael L. Semon (mlsemon@sega.net)
|
6
|
+
|
7
|
+
begin
|
8
|
+
# If Console.so is available, use that. Otherwise, we define
|
9
|
+
# equivalent functions in ruby (a tad slower)
|
10
|
+
# That dll should define everything in an identical interface
|
11
|
+
# to all the ruby code that the rescue below defines.
|
12
|
+
|
13
|
+
require "Console.so"
|
14
|
+
STDERR.print "Using faster, DLL Console.so\n" if $DEBUG
|
15
|
+
|
16
|
+
rescue Exception
|
17
|
+
|
18
|
+
STDERR.print "Using slower, non-DLL Console.rb\n" if $DEBUG
|
19
|
+
|
20
|
+
require 'Win32/Console/constants.rb'
|
21
|
+
require 'Win32/Console/api.rb'
|
22
|
+
|
23
|
+
end # rescue
|
24
|
+
|
25
|
+
module Win32
|
26
|
+
class Console
|
27
|
+
|
28
|
+
VERSION = '1.0'
|
29
|
+
|
30
|
+
include Win32::Console::Constants
|
31
|
+
|
32
|
+
def initialize( t = nil )
|
33
|
+
if t and ( t == STD_INPUT_HANDLE or t == STD_OUTPUT_HANDLE or
|
34
|
+
t == STD_ERROR_HANDLE )
|
35
|
+
@handle = API.GetStdHandle( t )
|
36
|
+
else
|
37
|
+
param1 = GENERIC_READ | GENERIC_WRITE
|
38
|
+
param2 = FILE_SHARE_READ | FILE_SHARE_WRITE
|
39
|
+
@handle = API.CreateConsoleScreenBuffer( param1, param2,
|
40
|
+
CONSOLE_TEXTMODE_BUFFER )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def Display
|
45
|
+
return API.SetConsoleActiveScreenBuffer(@handle)
|
46
|
+
end
|
47
|
+
|
48
|
+
def Select(type)
|
49
|
+
return API.SetStdHandle(type,@handle)
|
50
|
+
end
|
51
|
+
|
52
|
+
def Title(title = nil)
|
53
|
+
if title
|
54
|
+
return API.SetConsoleTitle(title)
|
55
|
+
else
|
56
|
+
return API.GetConsoleTitle()
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def WriteChar(s, col, row)
|
61
|
+
API.WriteConsoleOutputCharacter( @handle, s, col, row )
|
62
|
+
end
|
63
|
+
|
64
|
+
def ReadChar(size, col, row)
|
65
|
+
buffer = ' ' * size
|
66
|
+
if API.ReadConsoleOutputCharacter( @handle, buffer, size, col, row )
|
67
|
+
return buffer
|
68
|
+
else
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def WriteAttr(attr, col, row)
|
74
|
+
API.WriteConsoleOutputAttribute( @handle, attr, col, row )
|
75
|
+
end
|
76
|
+
|
77
|
+
def ReadAttr(size, col, row)
|
78
|
+
x = API.ReadConsoleOutputAttribute( @handle, size, col, row )
|
79
|
+
return x.unpack('c'*size)
|
80
|
+
end
|
81
|
+
|
82
|
+
def Cursor(*t)
|
83
|
+
col, row, size, visi = t
|
84
|
+
if col
|
85
|
+
row = -1 if !row
|
86
|
+
if col < 0 or row < 0
|
87
|
+
curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
88
|
+
col = curr_col if col < 0
|
89
|
+
row = curr_row if row < 0
|
90
|
+
end
|
91
|
+
API.SetConsoleCursorPosition( @handle, col, row )
|
92
|
+
if size and visi
|
93
|
+
curr_size, curr_visi = API.GetConsoleCursorInfo( @handle )
|
94
|
+
size = curr_size if size < 0
|
95
|
+
visi = curr_visi if visi < 0
|
96
|
+
size = 1 if size < 1
|
97
|
+
size = 99 if size > 99
|
98
|
+
API.SetConsoleCursorInfo( @handle, size, visi )
|
99
|
+
end
|
100
|
+
else
|
101
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
102
|
+
curr_size, curr_visi = API.GetConsoleCursorInfo( @handle )
|
103
|
+
return [ curr_col, curr_row, curr_size, curr_visi ]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def Write(s)
|
108
|
+
API.WriteConsole( @handle, s )
|
109
|
+
end
|
110
|
+
|
111
|
+
def WriteFile(s)
|
112
|
+
API.WriteFile( @handle, s)
|
113
|
+
end
|
114
|
+
|
115
|
+
def ReadRect( left, top, right, bottom )
|
116
|
+
col = right - left + 1
|
117
|
+
row = bottom - top + 1
|
118
|
+
size = col * row
|
119
|
+
buffer = ' ' * size * 4
|
120
|
+
if API.ReadConsoleOutput( @handle, buffer, col, row, 0, 0,
|
121
|
+
left, top, right, bottom )
|
122
|
+
#return buffer.unpack('US'*size) # for unicode
|
123
|
+
return buffer.unpack('axS'*size) # for ascii
|
124
|
+
else
|
125
|
+
return nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def WriteRect( buffer, left, top, right, bottom )
|
130
|
+
col = right - left + 1
|
131
|
+
row = bottom - top + 1
|
132
|
+
API.WriteConsoleOutput( @handle, buffer, col, row, 0, 0,
|
133
|
+
left, top, right, bottom )
|
134
|
+
end
|
135
|
+
|
136
|
+
def Scroll( left1, top1, right1, bottom1,
|
137
|
+
col, row, char, attr,
|
138
|
+
left2, top2, right2, bottom2 )
|
139
|
+
API.ScrollConsoleScreenBuffer(@handle, left1, top1, right1, bottom1,
|
140
|
+
col, row, char, attr,
|
141
|
+
left2, top2, right2, bottom2)
|
142
|
+
end
|
143
|
+
|
144
|
+
def MaxWindow(flag = nil)
|
145
|
+
if !flag
|
146
|
+
info = API.GetConsoleScreenBufferInfo(@handle)
|
147
|
+
return info[9], info[10]
|
148
|
+
else
|
149
|
+
return API.GetLargestConsoleWindowSize(@handle)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def Info()
|
154
|
+
return API.GetConsoleScreenBufferInfo( @handle )
|
155
|
+
end
|
156
|
+
|
157
|
+
def GetEvents()
|
158
|
+
return API.GetNumberOfConsoleInputEvents(@handle)
|
159
|
+
end
|
160
|
+
|
161
|
+
def Flush()
|
162
|
+
return API.FlushConsoleInputBuffer(@handle)
|
163
|
+
end
|
164
|
+
|
165
|
+
def InputChar(number = nil)
|
166
|
+
number = 1 unless number
|
167
|
+
buffer = ' ' * number
|
168
|
+
if API.ReadConsole(@handle, buffer, number) == number
|
169
|
+
return buffer
|
170
|
+
else
|
171
|
+
return nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def Input()
|
176
|
+
API.ReadConsoleInput(@handle)
|
177
|
+
end
|
178
|
+
|
179
|
+
def PeekInput()
|
180
|
+
API.PeekConsoleInput(@handle)
|
181
|
+
end
|
182
|
+
|
183
|
+
def Mode(mode = nil)
|
184
|
+
if mode
|
185
|
+
mode = mode.pack('L') if mode === Array
|
186
|
+
API.SetConsoleMode(@handle, mode)
|
187
|
+
else
|
188
|
+
begin
|
189
|
+
x = API.GetConsoleMode(@handle)
|
190
|
+
return x
|
191
|
+
rescue
|
192
|
+
return 9999
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def WriteInput(*t)
|
198
|
+
API.WriteConsoleInput(@handle, *t)
|
199
|
+
end
|
200
|
+
|
201
|
+
def Attr(*attr)
|
202
|
+
if attr.size > 0
|
203
|
+
API.SetConsoleTextAttribute( @handle, attr[0] )
|
204
|
+
else
|
205
|
+
info = API.GetConsoleScreenBufferInfo( @handle )
|
206
|
+
return info[4]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def Size(*t)
|
211
|
+
if t.size == 0
|
212
|
+
col, row = API.GetConsoleScreenBufferInfo(@handle )
|
213
|
+
return [col, row]
|
214
|
+
else
|
215
|
+
row = -1 if !t[1]
|
216
|
+
col = -1 if !t[0]
|
217
|
+
if col < 0 or row < 0
|
218
|
+
curr_col, curr_row = Size()
|
219
|
+
col = curr_col if col < 0
|
220
|
+
row = curr_row if row < 0
|
221
|
+
end
|
222
|
+
API.SetConsoleScreenBufferSize(@handle, row, col)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def Window(*t)
|
227
|
+
if t.size != 5
|
228
|
+
info = API.GetConsoleScreenBufferInfo( @handle )
|
229
|
+
return info[5..8]
|
230
|
+
else
|
231
|
+
API.SetConsoleWindowInfo(@handle, t[0], t[1], t[2], t[3], t[4])
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def FillAttr(attr, number = 1, col = -1, row = -1)
|
236
|
+
if col < 0 or row < 0
|
237
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
238
|
+
col = curr_col if col < 0
|
239
|
+
row = curr_row if row < 0
|
240
|
+
end
|
241
|
+
API.FillConsoleOutputAttribute(@handle, attr, number, col, row)
|
242
|
+
end
|
243
|
+
|
244
|
+
def FillChar(char, number, col = -1, row = -1)
|
245
|
+
if col < 0 or row < 0
|
246
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
247
|
+
col = curr_col if col < 0
|
248
|
+
row = curr_row if row < 0
|
249
|
+
end
|
250
|
+
API.FillConsoleOutputCharacter(@handle, char[0], number, col, row)
|
251
|
+
end
|
252
|
+
|
253
|
+
def Cls()
|
254
|
+
attr = ATTR_NORMAL
|
255
|
+
x, y = Size()
|
256
|
+
left, top, right , bottom = Window()
|
257
|
+
vx = right - left
|
258
|
+
vy = bottom - top
|
259
|
+
FillChar(' ', x*y, 0, 0)
|
260
|
+
FillAttr(attr, x*y, 0, 0)
|
261
|
+
Cursor(0,0)
|
262
|
+
Window(1,0,0,vx,vy)
|
263
|
+
end
|
264
|
+
|
265
|
+
def Console.Free()
|
266
|
+
API.FreeConsole()
|
267
|
+
end
|
268
|
+
|
269
|
+
def Console.Alloc()
|
270
|
+
API.AllocConsole()
|
271
|
+
end
|
272
|
+
|
273
|
+
def Console.MouseButtons()
|
274
|
+
API.GetNumberOfConsoleMouseButtons()
|
275
|
+
end
|
276
|
+
|
277
|
+
def Console.InputCP(codepage=nil)
|
278
|
+
if codepage
|
279
|
+
API.SetConsoleCP(codepage)
|
280
|
+
else
|
281
|
+
return API.GetConsoleCP()
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def Console.OutputCP(codepage=nil)
|
286
|
+
if codepage
|
287
|
+
API.SetConsoleOutputCP(codepage)
|
288
|
+
else
|
289
|
+
return API.GetConsoleOutputCP()
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def Console.GenerateCtrlEvent( type=nil, pid=nil )
|
294
|
+
type = API.constant('CTRL_C_EVENT') if type == nil
|
295
|
+
pid = 0 if pid == nil
|
296
|
+
API.GenerateConsoleCtrlEvent(type, pid)
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
FG_BLACK = 0
|
304
|
+
FG_BLUE = Win32::Console::API.constant("FOREGROUND_BLUE")
|
305
|
+
FG_LIGHTBLUE = Win32::Console::API.constant("FOREGROUND_BLUE")|
|
306
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
307
|
+
FG_RED = Win32::Console::API.constant("FOREGROUND_RED")
|
308
|
+
FG_LIGHTRED = Win32::Console::API.constant("FOREGROUND_RED")|
|
309
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
310
|
+
FG_GREEN = Win32::Console::API.constant("FOREGROUND_GREEN")
|
311
|
+
FG_LIGHTGREEN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
312
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
313
|
+
FG_MAGENTA = Win32::Console::API.constant("FOREGROUND_RED")|
|
314
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
315
|
+
FG_LIGHTMAGENTA = Win32::Console::API.constant("FOREGROUND_RED")|
|
316
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
317
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
318
|
+
FG_CYAN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
319
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
320
|
+
FG_LIGHTCYAN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
321
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
322
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
323
|
+
FG_BROWN = Win32::Console::API.constant("FOREGROUND_RED")|
|
324
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")
|
325
|
+
FG_YELLOW = Win32::Console::API.constant("FOREGROUND_RED")|
|
326
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
327
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
328
|
+
FG_GRAY = Win32::Console::API.constant("FOREGROUND_RED")|
|
329
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
330
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
331
|
+
FG_WHITE = Win32::Console::API.constant("FOREGROUND_RED")|
|
332
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
333
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
334
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
335
|
+
|
336
|
+
BG_BLACK = 0
|
337
|
+
BG_BLUE = Win32::Console::API.constant("BACKGROUND_BLUE")
|
338
|
+
BG_LIGHTBLUE = Win32::Console::API.constant("BACKGROUND_BLUE")|
|
339
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
340
|
+
BG_RED = Win32::Console::API.constant("BACKGROUND_RED")
|
341
|
+
BG_LIGHTRED = Win32::Console::API.constant("BACKGROUND_RED")|
|
342
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
343
|
+
BG_GREEN = Win32::Console::API.constant("BACKGROUND_GREEN")
|
344
|
+
BG_LIGHTGREEN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
345
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
346
|
+
BG_MAGENTA = Win32::Console::API.constant("BACKGROUND_RED")|
|
347
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
348
|
+
BG_LIGHTMAGENTA = Win32::Console::API.constant("BACKGROUND_RED")|
|
349
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
350
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
351
|
+
BG_CYAN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
352
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
353
|
+
BG_LIGHTCYAN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
354
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
355
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
356
|
+
BG_BROWN = Win32::Console::API.constant("BACKGROUND_RED")|
|
357
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")
|
358
|
+
BG_YELLOW = Win32::Console::API.constant("BACKGROUND_RED")|
|
359
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
360
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
361
|
+
BG_GRAY = Win32::Console::API.constant("BACKGROUND_RED")|
|
362
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
363
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
364
|
+
BG_WHITE = Win32::Console::API.constant("BACKGROUND_RED")|
|
365
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
366
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
367
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
368
|
+
|
369
|
+
ATTR_NORMAL = FG_GRAY | BG_BLACK
|
370
|
+
ATTR_INVERSE = FG_BLACK | BG_GRAY
|
371
|
+
|
372
|
+
include Win32::Console::Constants
|
data/lib/win32console.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'Win32/Console/ANSI'
|
data/test/test_cursor.rb
ADDED
data/test/test_mouse.rb
ADDED
@@ -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
|
+
|
data/test/test_title.rb
ADDED
data/test/test_write.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
include Term::ANSIColor
|
6
|
+
rescue LoadError
|
7
|
+
puts "You need term-ansicolor gem installed to run this test"
|
8
|
+
puts "Please 'gem install term-ansicolor' and try again."
|
9
|
+
end
|
10
|
+
|
11
|
+
require "benchmark"
|
12
|
+
require "Win32/Console/ANSI"
|
13
|
+
|
14
|
+
Benchmark.bm do |x|
|
15
|
+
num = 100
|
16
|
+
x.report("#{num} times") {
|
17
|
+
0.upto(num) {
|
18
|
+
print "\e[2J"
|
19
|
+
|
20
|
+
print red, bold, "Usage as constants:", reset, "\n"
|
21
|
+
|
22
|
+
print clear, "clear", reset, reset, "reset", reset,
|
23
|
+
bold, "bold", reset, dark, "dark", reset,
|
24
|
+
underscore, "underscore", reset, blink, "blink", reset,
|
25
|
+
negative, "negative", reset, concealed, "concealed", reset, "|\n",
|
26
|
+
black, "black", reset, red, "red", reset, green, "green", reset,
|
27
|
+
yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
|
28
|
+
cyan, "cyan", reset, white, "white", reset, "|\n",
|
29
|
+
on_black, "on_black", reset, on_red, "on_red", reset,
|
30
|
+
on_green, "on_green", reset, on_yellow, "on_yellow", reset,
|
31
|
+
on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
|
32
|
+
on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
|
33
|
+
print "\e[s\e[20P.................."
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: win32console
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: x86-mingw32
|
6
|
+
authors:
|
7
|
+
- Original Library by Gonzalo Garramuno, Gem by Justin Bailey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-22 00:00:00 -02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "This gem packages Gonzalo Garramuno's Win32::Console project, and includes a compiled binary for speed. The Win32::Console project's home can be found at: http://rubyforge.org/projects/win32console The gem project can be found at http://rubyforge.org/projects/winconsole"
|
17
|
+
email: ggarra @nospam@ advancedsl.com.ar, jgbailey @nospan@ gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
- README_GEM.txt
|
25
|
+
- INSTALL.txt
|
26
|
+
- HISTORY.txt
|
27
|
+
- HISTORY_GEM.txt
|
28
|
+
files:
|
29
|
+
- doc/Console.rdoc
|
30
|
+
- doc/Console_ANSI.rdoc
|
31
|
+
- ext/Console.cpp
|
32
|
+
- ext/extconf.rb
|
33
|
+
- lib/Win32/Console/ANSI.rb
|
34
|
+
- lib/Win32/Console/api.rb
|
35
|
+
- lib/Win32/Console/constants.rb
|
36
|
+
- lib/Win32/Console.rb
|
37
|
+
- lib/win32console.rb
|
38
|
+
- test/test_cursor.rb
|
39
|
+
- test/test_mouse.rb
|
40
|
+
- test/test_readinput.rb
|
41
|
+
- test/test_readoutput.rb
|
42
|
+
- test/test_sendevent.rb
|
43
|
+
- test/test_title.rb
|
44
|
+
- test/test_write.rb
|
45
|
+
- Rakefile
|
46
|
+
- README.txt
|
47
|
+
- README_GEM.txt
|
48
|
+
- INSTALL.txt
|
49
|
+
- HISTORY.txt
|
50
|
+
- HISTORY_GEM.txt
|
51
|
+
- lib/Console.so
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://rubyforge.org/projects/winconsole
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --title
|
57
|
+
- Win32Console Gem -- Gem for Win32::Console Project
|
58
|
+
- --main
|
59
|
+
- README_GEM.txt
|
60
|
+
- --line-numbers
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: http://rubyforge.org/projects/winconsole
|
78
|
+
rubygems_version: 1.3.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: A library giving the Win32 console ANSI escape sequence support.
|
82
|
+
test_files: []
|
83
|
+
|