win32console 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +119 -0
- data/Manifest.txt +22 -0
- data/README.txt +63 -0
- data/Rakefile +54 -0
- data/ext/Console_ext/Console.c +1216 -0
- data/ext/Console_ext/extconf.rb +18 -0
- data/extra/Console.rdoc +690 -0
- data/extra/Console_ANSI.rdoc +302 -0
- data/lib/Win32/Console.rb +362 -0
- data/lib/Win32/Console/ANSI.rb +336 -0
- data/lib/Win32/Console/api.rb +342 -0
- data/lib/Win32/Console/constants.rb +66 -0
- data/lib/win32console.rb +1 -0
- data/tasks/gem.rake +31 -0
- data/tasks/native.rake +14 -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 +126 -0
@@ -0,0 +1,302 @@
|
|
1
|
+
#
|
2
|
+
# = NAME
|
3
|
+
#
|
4
|
+
# Win32::Console::ANSI - Ruby extension to emulate ANSI console on Win32 system.
|
5
|
+
#
|
6
|
+
# = SYNOPSIS
|
7
|
+
#
|
8
|
+
# require "Win32::Console::ANSI"
|
9
|
+
#
|
10
|
+
# puts "\e[1;34mThis text is bold blue.\e[0m"
|
11
|
+
# puts "This text is normal.""
|
12
|
+
# puts "\e[33;45;1mBold yellow on magenta.\e[0m"
|
13
|
+
# puts "This text is normal."
|
14
|
+
#
|
15
|
+
# With the Term::ANSIColor module one increases the readability:
|
16
|
+
#
|
17
|
+
# require "Win32::Console::ANSI"
|
18
|
+
# require "Term::ANSIColor"
|
19
|
+
#
|
20
|
+
# puts color 'bold blue'
|
21
|
+
# puts "This text is bold blue."
|
22
|
+
# puts color 'reset'
|
23
|
+
# puts "This text is normal."
|
24
|
+
# puts colored ("Bold yellow on magenta.", 'bold yellow on_magenta')
|
25
|
+
# puts "This text is normal."
|
26
|
+
#
|
27
|
+
# And even more with Term::ANSIScreen:
|
28
|
+
#
|
29
|
+
# require "Win32::Console::ANSI;
|
30
|
+
# require "Term::ANSIScreen qw/:color :cursor :screen/;
|
31
|
+
#
|
32
|
+
# locate 1, 1; puts "@ This is (1,1)", savepos;
|
33
|
+
# puts locate(24,60), "@ This is (24,60)"; loadpos;
|
34
|
+
# puts down(2), clline, "@ This is (3,16)";
|
35
|
+
# setscroll 1, 20;
|
36
|
+
# color 'black on white'; clline;
|
37
|
+
# puts "This line is black on white.";
|
38
|
+
# puts color 'reset'; puts "This text is normal.";
|
39
|
+
# puts colored ("This text is bold blue.", 'bold blue');
|
40
|
+
# puts "This text is normal.";
|
41
|
+
# puts colored ['bold blue'], "This text is bold blue.";
|
42
|
+
# puts "This text is normal.";
|
43
|
+
#
|
44
|
+
# = DESCRIPTION
|
45
|
+
#
|
46
|
+
# Windows NT/2000/XP does not support ANSI escape sequences in Win32 Console
|
47
|
+
# applications. This module emulates an ANSI console for the script which
|
48
|
+
# uses it.
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# == Escape sequences for Cursor Movement
|
52
|
+
#
|
53
|
+
# * \e[#A
|
54
|
+
#
|
55
|
+
# CUU: CUrsor Up: Moves the cursor up by the specified number of lines without
|
56
|
+
# changing columns. If the cursor is already on the top line, this sequence
|
57
|
+
# is ignored. \e[A is equivalent to \e[1A.
|
58
|
+
#
|
59
|
+
# * \e[#B
|
60
|
+
#
|
61
|
+
# CUD: CUrsor Down: Moves the cursor down by the specified number of lines
|
62
|
+
# without changing columns. If the cursor is already on the bottom line,
|
63
|
+
# this sequence is ignored. \e[B is equivalent to \e[1B.
|
64
|
+
#
|
65
|
+
# * \e[#C
|
66
|
+
#
|
67
|
+
# CUF: CUrsor Forward: Moves the cursor forward by the specified number of
|
68
|
+
# columns without changing lines. If the cursor is already in the
|
69
|
+
# rightmost column, this sequence is ignored. \e[C is equivalent to \e[1C.
|
70
|
+
#
|
71
|
+
# * \e[#D
|
72
|
+
#
|
73
|
+
# CUB: CUrsor Backward: Moves the cursor back by the specified number of
|
74
|
+
# columns without changing lines. If the cursor is already in the leftmost
|
75
|
+
# column, this sequence is ignored. \e[D is equivalent to \e[1D.
|
76
|
+
#
|
77
|
+
# * \e[#E
|
78
|
+
#
|
79
|
+
# CNL: Cursor Next Line: Moves the cursor down the indicated # of rows, to
|
80
|
+
# column 1. \e[E is equivalent to \e[1E.
|
81
|
+
#
|
82
|
+
# * \e[#F
|
83
|
+
#
|
84
|
+
# CPL: Cursor Preceding Line: Moves the cursor up the indicated # of rows,
|
85
|
+
# to column 1. \e[F is equivalent to \e[1F.
|
86
|
+
#
|
87
|
+
# * \e[#G
|
88
|
+
#
|
89
|
+
# CHA: Cursor Horizontal Absolute: Moves the cursor to indicated column in
|
90
|
+
# current row. \e[G is equivalent to \e[1G.
|
91
|
+
#
|
92
|
+
# * \e[#;#H
|
93
|
+
#
|
94
|
+
# CUP: CUrsor Position: Moves the cursor to the specified position. The first #
|
95
|
+
# specifies the line number, the second # specifies the column.
|
96
|
+
# If you do not specify a position, the cursor moves to the
|
97
|
+
# home position: the upper-left corner of the screen (line 1, column 1).
|
98
|
+
#
|
99
|
+
# * \e[#;#f
|
100
|
+
#
|
101
|
+
# HVP: Horizontal and Vertical Position.
|
102
|
+
# Works the same way as the preceding escape sequence.
|
103
|
+
#
|
104
|
+
# * \e[s
|
105
|
+
#
|
106
|
+
# SCP: Save Cursor Position: Saves the current cursor position. You can move
|
107
|
+
# the cursor to the saved cursor position by using the Restore Cursor
|
108
|
+
# Position sequence.
|
109
|
+
#
|
110
|
+
# * \e[u
|
111
|
+
#
|
112
|
+
# RCP: Restore Cursor Position: Returns the cursor to the position stored
|
113
|
+
# by the Save Cursor Position sequence.
|
114
|
+
#
|
115
|
+
# == Escape sequences for Display Edition
|
116
|
+
#
|
117
|
+
# * \e[#J
|
118
|
+
#
|
119
|
+
# ED: Erase Display:
|
120
|
+
#
|
121
|
+
# * \e[0J
|
122
|
+
#
|
123
|
+
# Clears the screen from cursor to end of display. The cursor position is unchanged.
|
124
|
+
#
|
125
|
+
# * \e[1J
|
126
|
+
#
|
127
|
+
# Clears the screen from start to cursor. The cursor position is unchanged.
|
128
|
+
#
|
129
|
+
# * \e[2J
|
130
|
+
#
|
131
|
+
# Clears the screen and moves the cursor to the home position (line 1, column 1).
|
132
|
+
#
|
133
|
+
# \e[J is equivalent to \e[0J. (Some terminal/emulators respond to \e[J as if
|
134
|
+
# it were \e[2J. Here, the default is 0; it's the norm)
|
135
|
+
#
|
136
|
+
# * \e[#K
|
137
|
+
#
|
138
|
+
# EL: Erase Line:
|
139
|
+
#
|
140
|
+
# * \e[0K
|
141
|
+
#
|
142
|
+
# Clears all characters from the cursor position to the end of the line
|
143
|
+
# (including the character at the cursor position).
|
144
|
+
# The cursor position is unchanged.
|
145
|
+
#
|
146
|
+
# * \e[1K
|
147
|
+
#
|
148
|
+
# Clears all characters from start of line to the cursor position.
|
149
|
+
# (including the character at the cursor position).
|
150
|
+
# The cursor position is unchanged.
|
151
|
+
#
|
152
|
+
# * \e[2K
|
153
|
+
#
|
154
|
+
# Clears all characters of the whole line.
|
155
|
+
# The cursor position is unchanged.
|
156
|
+
#
|
157
|
+
# \e[K is equivalent to \e[0K.
|
158
|
+
#
|
159
|
+
# * \e[#L
|
160
|
+
#
|
161
|
+
# IL: Insert Lines: The cursor line and all lines below it move down # lines,
|
162
|
+
# leaving blank space. The cursor position is unchanged. The bottommost #
|
163
|
+
# lines are lost. \e[L is equivalent to \e[1L.
|
164
|
+
#
|
165
|
+
# * \e[#M
|
166
|
+
#
|
167
|
+
# DL: Delete Line: The block of # lines at and below the cursor are deleted;
|
168
|
+
# all lines below them move up # lines to fill in the gap, leaving # blank
|
169
|
+
# lines at the bottom of the screen. The cursor position is unchanged.
|
170
|
+
# \e[M is equivalent to \e[1M.
|
171
|
+
#
|
172
|
+
# * \e#\@
|
173
|
+
#
|
174
|
+
# ICH: Insert CHaracter: The cursor character and all characters to the right
|
175
|
+
# of it move right # columns, leaving behind blank space.
|
176
|
+
# The cursor position is unchanged. The rightmost # characters on the line are lost.
|
177
|
+
#
|
178
|
+
# * \e[#P
|
179
|
+
#
|
180
|
+
# DCH: Delete CHaracter: The block of # characters at and to the right of the
|
181
|
+
# cursor are deleted; all characters to the right of it move left # columns,
|
182
|
+
# leaving behind blank space. The cursor position is unchanged.
|
183
|
+
# \e[P is equivalent to \e[1P.
|
184
|
+
#
|
185
|
+
#
|
186
|
+
# == Escape sequences for Set Graphics Rendition
|
187
|
+
#
|
188
|
+
# * \e[#;...;#m
|
189
|
+
#
|
190
|
+
# SGM: Set Graphics Mode: Calls the graphics functions specified by the
|
191
|
+
# following values. These specified functions remain active until the next
|
192
|
+
# occurrence of this escape sequence. Graphics mode changes the colors and
|
193
|
+
# attributes of text (such as bold and underline) displayed on the
|
194
|
+
# screen.
|
195
|
+
#
|
196
|
+
# * Text attributes
|
197
|
+
#
|
198
|
+
# 0 All attributes off
|
199
|
+
# 1 Bold on
|
200
|
+
# 4 Underscore on
|
201
|
+
# 7 Reverse video on
|
202
|
+
# 8 Concealed on
|
203
|
+
#
|
204
|
+
# 21 Bold off
|
205
|
+
# 24 Underscore off
|
206
|
+
# 27 Reverse video off
|
207
|
+
# 28 Concealed off
|
208
|
+
#
|
209
|
+
# * Foreground colors
|
210
|
+
#
|
211
|
+
# 30 Black
|
212
|
+
# 31 Red
|
213
|
+
# 32 Green
|
214
|
+
# 33 Yellow
|
215
|
+
# 34 Blue
|
216
|
+
# 35 Magenta
|
217
|
+
# 36 Cyan
|
218
|
+
# 37 White
|
219
|
+
#
|
220
|
+
# * Background colors
|
221
|
+
#
|
222
|
+
# 40 Black
|
223
|
+
# 41 Red
|
224
|
+
# 42 Green
|
225
|
+
# 43 Yellow
|
226
|
+
# 44 Blue
|
227
|
+
# 45 Magenta
|
228
|
+
# 46 Cyan
|
229
|
+
# 47 White
|
230
|
+
#
|
231
|
+
# \e[m is equivalent to \e0m.
|
232
|
+
#
|
233
|
+
# == Escape sequences for Select Character Set
|
234
|
+
#
|
235
|
+
# * \e(U
|
236
|
+
#
|
237
|
+
# Select null mapping - straight to character from the codepage of the console.
|
238
|
+
#
|
239
|
+
# * \e(K
|
240
|
+
#
|
241
|
+
# Select Windows to DOS mapping, if the corresponding map exist; no effect
|
242
|
+
# otherwise. This is the default mapping (if the map exist, of course). It's
|
243
|
+
# useful becarequire "one types the script with a Windows-based editor (using a
|
244
|
+
# Windows codepage) and the script prints its messages on the console using
|
245
|
+
# another codepage: without translation, the characters with a code greatest
|
246
|
+
# than 127 are different and the printed messages may be not readable.
|
247
|
+
#
|
248
|
+
# The conversion is done by the module Encode if it is installed (it's a
|
249
|
+
# standard module with Perl5.8, not Ruby yet). Otherwise, the conversion is limited to the
|
250
|
+
# following couples:
|
251
|
+
#
|
252
|
+
# WinLatin1 (cp1252) to DOSLatin1 (cp850)
|
253
|
+
# WinLatin1 (cp1252) to DOSLatinUS (cp437)
|
254
|
+
# WinLatin2 (cp1250) to DOSLatin2 (cp852)
|
255
|
+
# WinCyrillic(cp1251) to DOSCyrillic (cp855)
|
256
|
+
#
|
257
|
+
# * \e(#X
|
258
|
+
#
|
259
|
+
# This escape sequence is I<not> standard! It's an experimental one, just for
|
260
|
+
# fun :-)
|
261
|
+
#
|
262
|
+
# If <i>and only if</i> the console uses an Unicode police, it is possible to
|
263
|
+
# change its codepage with this escape sequence. No effect with an ordinary
|
264
|
+
# "Raster Font". (For Windows NT/2000/XP the currently available Unicode
|
265
|
+
# console font is the Lucida Console TrueType font.)
|
266
|
+
# # is the number of the codepage needed, 855 for cp855 for instance.
|
267
|
+
#
|
268
|
+
#
|
269
|
+
# = LIMITATIONS
|
270
|
+
#
|
271
|
+
# * Due to DOS-console limitations, the blink mode (text attributes 5 and 25) is not implemented.
|
272
|
+
#
|
273
|
+
# = SEE ALSO
|
274
|
+
#
|
275
|
+
# <b>Win32::Console</b>, <b>Term::ANSIColor</b>, <b>Term::ANSIScreen</b>.
|
276
|
+
#
|
277
|
+
# = AUTHOR
|
278
|
+
#
|
279
|
+
# J-L Morel jl_morel@bribes.org
|
280
|
+
#
|
281
|
+
# Home page: http://www.bribes.org/perl/wANSIConsole.html
|
282
|
+
#
|
283
|
+
# Gonzalo Garramu�o GGarramuno@aol.com Ruby port
|
284
|
+
#
|
285
|
+
# = CREDITS
|
286
|
+
#
|
287
|
+
# Render unto C�sar the things which are C�sar's...
|
288
|
+
#
|
289
|
+
# This module requires the module Win32::Console. Thanks to Aldo Calpini.
|
290
|
+
#
|
291
|
+
# The method used to overload the print function is due to Matt Sergeant
|
292
|
+
# (see his module Win32::ASP).
|
293
|
+
#
|
294
|
+
# = COPYRIGHT
|
295
|
+
#
|
296
|
+
# Copyright (c) 2004 Gonzalo Garramu�o. All rights reserved.
|
297
|
+
# Copyright (c) 2003 J-L Morel. All rights reserved.
|
298
|
+
#
|
299
|
+
# This program is free software; you can redistribute it and/or modify it under
|
300
|
+
# the terms of the Artistic License.
|
301
|
+
#
|
302
|
+
#
|
@@ -0,0 +1,362 @@
|
|
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
|
+
# support multiple ruby version (fat binaries under windows)
|
8
|
+
begin
|
9
|
+
require 'Console_ext'
|
10
|
+
rescue LoadError
|
11
|
+
RUBY_VERSION =~ /(\d+.\d+)/
|
12
|
+
require "#{$1}/Console_ext"
|
13
|
+
end
|
14
|
+
|
15
|
+
module Win32
|
16
|
+
class Console
|
17
|
+
|
18
|
+
VERSION = '1.0'
|
19
|
+
|
20
|
+
include Win32::Console::Constants
|
21
|
+
|
22
|
+
def initialize( t = nil )
|
23
|
+
if t and ( t == STD_INPUT_HANDLE or t == STD_OUTPUT_HANDLE or
|
24
|
+
t == STD_ERROR_HANDLE )
|
25
|
+
@handle = API.GetStdHandle( t )
|
26
|
+
else
|
27
|
+
param1 = GENERIC_READ | GENERIC_WRITE
|
28
|
+
param2 = FILE_SHARE_READ | FILE_SHARE_WRITE
|
29
|
+
@handle = API.CreateConsoleScreenBuffer( param1, param2,
|
30
|
+
CONSOLE_TEXTMODE_BUFFER )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def Display
|
35
|
+
return API.SetConsoleActiveScreenBuffer(@handle)
|
36
|
+
end
|
37
|
+
|
38
|
+
def Select(type)
|
39
|
+
return API.SetStdHandle(type,@handle)
|
40
|
+
end
|
41
|
+
|
42
|
+
def Title(title = nil)
|
43
|
+
if title
|
44
|
+
return API.SetConsoleTitle(title)
|
45
|
+
else
|
46
|
+
return API.GetConsoleTitle()
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def WriteChar(s, col, row)
|
51
|
+
API.WriteConsoleOutputCharacter( @handle, s, col, row )
|
52
|
+
end
|
53
|
+
|
54
|
+
def ReadChar(size, col, row)
|
55
|
+
buffer = ' ' * size
|
56
|
+
if API.ReadConsoleOutputCharacter( @handle, buffer, size, col, row )
|
57
|
+
return buffer
|
58
|
+
else
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def WriteAttr(attr, col, row)
|
64
|
+
API.WriteConsoleOutputAttribute( @handle, attr, col, row )
|
65
|
+
end
|
66
|
+
|
67
|
+
def ReadAttr(size, col, row)
|
68
|
+
x = API.ReadConsoleOutputAttribute( @handle, size, col, row )
|
69
|
+
return x.unpack('c'*size)
|
70
|
+
end
|
71
|
+
|
72
|
+
def Cursor(*t)
|
73
|
+
col, row, size, visi = t
|
74
|
+
if col
|
75
|
+
row = -1 if !row
|
76
|
+
if col < 0 or row < 0
|
77
|
+
curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
78
|
+
col = curr_col if col < 0
|
79
|
+
row = curr_row if row < 0
|
80
|
+
end
|
81
|
+
API.SetConsoleCursorPosition( @handle, col, row )
|
82
|
+
if size and visi
|
83
|
+
curr_size, curr_visi = API.GetConsoleCursorInfo( @handle )
|
84
|
+
size = curr_size if size < 0
|
85
|
+
visi = curr_visi if visi < 0
|
86
|
+
size = 1 if size < 1
|
87
|
+
size = 99 if size > 99
|
88
|
+
API.SetConsoleCursorInfo( @handle, size, visi )
|
89
|
+
end
|
90
|
+
else
|
91
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
92
|
+
curr_size, curr_visi = API.GetConsoleCursorInfo( @handle )
|
93
|
+
return [ curr_col, curr_row, curr_size, curr_visi ]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def Write(s)
|
98
|
+
API.WriteConsole( @handle, s )
|
99
|
+
end
|
100
|
+
|
101
|
+
def WriteFile(s)
|
102
|
+
API.WriteFile( @handle, s)
|
103
|
+
end
|
104
|
+
|
105
|
+
def ReadRect( left, top, right, bottom )
|
106
|
+
col = right - left + 1
|
107
|
+
row = bottom - top + 1
|
108
|
+
size = col * row
|
109
|
+
buffer = ' ' * size * 4
|
110
|
+
if API.ReadConsoleOutput( @handle, buffer, col, row, 0, 0,
|
111
|
+
left, top, right, bottom )
|
112
|
+
#return buffer.unpack('US'*size) # for unicode
|
113
|
+
return buffer.unpack('axS'*size) # for ascii
|
114
|
+
else
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def WriteRect( buffer, left, top, right, bottom )
|
120
|
+
col = right - left + 1
|
121
|
+
row = bottom - top + 1
|
122
|
+
API.WriteConsoleOutput( @handle, buffer, col, row, 0, 0,
|
123
|
+
left, top, right, bottom )
|
124
|
+
end
|
125
|
+
|
126
|
+
def Scroll( left1, top1, right1, bottom1,
|
127
|
+
col, row, char, attr,
|
128
|
+
left2, top2, right2, bottom2 )
|
129
|
+
API.ScrollConsoleScreenBuffer(@handle, left1, top1, right1, bottom1,
|
130
|
+
col, row, char, attr,
|
131
|
+
left2, top2, right2, bottom2)
|
132
|
+
end
|
133
|
+
|
134
|
+
def MaxWindow(flag = nil)
|
135
|
+
if !flag
|
136
|
+
info = API.GetConsoleScreenBufferInfo(@handle)
|
137
|
+
return info[9], info[10]
|
138
|
+
else
|
139
|
+
return API.GetLargestConsoleWindowSize(@handle)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def Info()
|
144
|
+
return API.GetConsoleScreenBufferInfo( @handle )
|
145
|
+
end
|
146
|
+
|
147
|
+
def GetEvents()
|
148
|
+
return API.GetNumberOfConsoleInputEvents(@handle)
|
149
|
+
end
|
150
|
+
|
151
|
+
def Flush()
|
152
|
+
return API.FlushConsoleInputBuffer(@handle)
|
153
|
+
end
|
154
|
+
|
155
|
+
def InputChar(number = nil)
|
156
|
+
number = 1 unless number
|
157
|
+
buffer = ' ' * number
|
158
|
+
if API.ReadConsole(@handle, buffer, number) == number
|
159
|
+
return buffer
|
160
|
+
else
|
161
|
+
return nil
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def Input()
|
166
|
+
API.ReadConsoleInput(@handle)
|
167
|
+
end
|
168
|
+
|
169
|
+
def PeekInput()
|
170
|
+
API.PeekConsoleInput(@handle)
|
171
|
+
end
|
172
|
+
|
173
|
+
def Mode(mode = nil)
|
174
|
+
if mode
|
175
|
+
mode = mode.pack('L') if mode === Array
|
176
|
+
API.SetConsoleMode(@handle, mode)
|
177
|
+
else
|
178
|
+
begin
|
179
|
+
x = API.GetConsoleMode(@handle)
|
180
|
+
return x
|
181
|
+
rescue
|
182
|
+
return 9999
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def WriteInput(*t)
|
188
|
+
API.WriteConsoleInput(@handle, *t)
|
189
|
+
end
|
190
|
+
|
191
|
+
def Attr(*attr)
|
192
|
+
if attr.size > 0
|
193
|
+
API.SetConsoleTextAttribute( @handle, attr[0] )
|
194
|
+
else
|
195
|
+
info = API.GetConsoleScreenBufferInfo( @handle )
|
196
|
+
return info[4]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def Size(*t)
|
201
|
+
if t.size == 0
|
202
|
+
col, row = API.GetConsoleScreenBufferInfo(@handle )
|
203
|
+
return [col, row]
|
204
|
+
else
|
205
|
+
row = -1 if !t[1]
|
206
|
+
col = -1 if !t[0]
|
207
|
+
if col < 0 or row < 0
|
208
|
+
curr_col, curr_row = Size()
|
209
|
+
col = curr_col if col < 0
|
210
|
+
row = curr_row if row < 0
|
211
|
+
end
|
212
|
+
API.SetConsoleScreenBufferSize(@handle, row, col)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def Window(*t)
|
217
|
+
if t.size != 5
|
218
|
+
info = API.GetConsoleScreenBufferInfo( @handle )
|
219
|
+
return info[5..8]
|
220
|
+
else
|
221
|
+
API.SetConsoleWindowInfo(@handle, t[0], t[1], t[2], t[3], t[4])
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def FillAttr(attr, number = 1, col = -1, row = -1)
|
226
|
+
if col < 0 or row < 0
|
227
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
228
|
+
col = curr_col if col < 0
|
229
|
+
row = curr_row if row < 0
|
230
|
+
end
|
231
|
+
API.FillConsoleOutputAttribute(@handle, attr, number, col, row)
|
232
|
+
end
|
233
|
+
|
234
|
+
def FillChar(char, number, col = -1, row = -1)
|
235
|
+
if col < 0 or row < 0
|
236
|
+
d, d, curr_col, curr_row = API.GetConsoleScreenBufferInfo(@handle)
|
237
|
+
col = curr_col if col < 0
|
238
|
+
row = curr_row if row < 0
|
239
|
+
end
|
240
|
+
API.FillConsoleOutputCharacter(@handle, char[0], number, col, row)
|
241
|
+
end
|
242
|
+
|
243
|
+
def Cls()
|
244
|
+
attr = ATTR_NORMAL
|
245
|
+
x, y = Size()
|
246
|
+
left, top, right , bottom = Window()
|
247
|
+
vx = right - left
|
248
|
+
vy = bottom - top
|
249
|
+
FillChar(' ', x*y, 0, 0)
|
250
|
+
FillAttr(attr, x*y, 0, 0)
|
251
|
+
Cursor(0,0)
|
252
|
+
Window(1,0,0,vx,vy)
|
253
|
+
end
|
254
|
+
|
255
|
+
def Console.Free()
|
256
|
+
API.FreeConsole()
|
257
|
+
end
|
258
|
+
|
259
|
+
def Console.Alloc()
|
260
|
+
API.AllocConsole()
|
261
|
+
end
|
262
|
+
|
263
|
+
def Console.MouseButtons()
|
264
|
+
API.GetNumberOfConsoleMouseButtons()
|
265
|
+
end
|
266
|
+
|
267
|
+
def Console.InputCP(codepage=nil)
|
268
|
+
if codepage
|
269
|
+
API.SetConsoleCP(codepage)
|
270
|
+
else
|
271
|
+
return API.GetConsoleCP()
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def Console.OutputCP(codepage=nil)
|
276
|
+
if codepage
|
277
|
+
API.SetConsoleOutputCP(codepage)
|
278
|
+
else
|
279
|
+
return API.GetConsoleOutputCP()
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def Console.GenerateCtrlEvent( type=nil, pid=nil )
|
284
|
+
type = API.constant('CTRL_C_EVENT') if type == nil
|
285
|
+
pid = 0 if pid == nil
|
286
|
+
API.GenerateConsoleCtrlEvent(type, pid)
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
FG_BLACK = 0
|
294
|
+
FG_BLUE = Win32::Console::API.constant("FOREGROUND_BLUE")
|
295
|
+
FG_LIGHTBLUE = Win32::Console::API.constant("FOREGROUND_BLUE")|
|
296
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
297
|
+
FG_RED = Win32::Console::API.constant("FOREGROUND_RED")
|
298
|
+
FG_LIGHTRED = Win32::Console::API.constant("FOREGROUND_RED")|
|
299
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
300
|
+
FG_GREEN = Win32::Console::API.constant("FOREGROUND_GREEN")
|
301
|
+
FG_LIGHTGREEN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
302
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
303
|
+
FG_MAGENTA = Win32::Console::API.constant("FOREGROUND_RED")|
|
304
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
305
|
+
FG_LIGHTMAGENTA = Win32::Console::API.constant("FOREGROUND_RED")|
|
306
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
307
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
308
|
+
FG_CYAN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
309
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
310
|
+
FG_LIGHTCYAN = Win32::Console::API.constant("FOREGROUND_GREEN")|
|
311
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
312
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
313
|
+
FG_BROWN = Win32::Console::API.constant("FOREGROUND_RED")|
|
314
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")
|
315
|
+
FG_YELLOW = Win32::Console::API.constant("FOREGROUND_RED")|
|
316
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
317
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
318
|
+
FG_GRAY = Win32::Console::API.constant("FOREGROUND_RED")|
|
319
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
320
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")
|
321
|
+
FG_WHITE = Win32::Console::API.constant("FOREGROUND_RED")|
|
322
|
+
Win32::Console::API.constant("FOREGROUND_GREEN")|
|
323
|
+
Win32::Console::API.constant("FOREGROUND_BLUE")|
|
324
|
+
Win32::Console::API.constant("FOREGROUND_INTENSITY")
|
325
|
+
|
326
|
+
BG_BLACK = 0
|
327
|
+
BG_BLUE = Win32::Console::API.constant("BACKGROUND_BLUE")
|
328
|
+
BG_LIGHTBLUE = Win32::Console::API.constant("BACKGROUND_BLUE")|
|
329
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
330
|
+
BG_RED = Win32::Console::API.constant("BACKGROUND_RED")
|
331
|
+
BG_LIGHTRED = Win32::Console::API.constant("BACKGROUND_RED")|
|
332
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
333
|
+
BG_GREEN = Win32::Console::API.constant("BACKGROUND_GREEN")
|
334
|
+
BG_LIGHTGREEN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
335
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
336
|
+
BG_MAGENTA = Win32::Console::API.constant("BACKGROUND_RED")|
|
337
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
338
|
+
BG_LIGHTMAGENTA = Win32::Console::API.constant("BACKGROUND_RED")|
|
339
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
340
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
341
|
+
BG_CYAN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
342
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
343
|
+
BG_LIGHTCYAN = Win32::Console::API.constant("BACKGROUND_GREEN")|
|
344
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
345
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
346
|
+
BG_BROWN = Win32::Console::API.constant("BACKGROUND_RED")|
|
347
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")
|
348
|
+
BG_YELLOW = Win32::Console::API.constant("BACKGROUND_RED")|
|
349
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
350
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
351
|
+
BG_GRAY = Win32::Console::API.constant("BACKGROUND_RED")|
|
352
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
353
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")
|
354
|
+
BG_WHITE = Win32::Console::API.constant("BACKGROUND_RED")|
|
355
|
+
Win32::Console::API.constant("BACKGROUND_GREEN")|
|
356
|
+
Win32::Console::API.constant("BACKGROUND_BLUE")|
|
357
|
+
Win32::Console::API.constant("BACKGROUND_INTENSITY")
|
358
|
+
|
359
|
+
ATTR_NORMAL = FG_GRAY | BG_BLACK
|
360
|
+
ATTR_INVERSE = FG_BLACK | BG_GRAY
|
361
|
+
|
362
|
+
include Win32::Console::Constants
|