conio 1.0
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/LICENSE +28 -0
- data/README +67 -0
- data/Rakefile +40 -0
- data/lib/conio.rb +579 -0
- data/lib/libconio.so +0 -0
- data/test/test.rb +298 -0
- metadata +67 -0
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
= Ruby Conio 1.0
|
3
|
+
|
4
|
+
LICENSE
|
5
|
+
|
6
|
+
* Author: Gabriele Secci
|
7
|
+
* Web: http://www.ragnetto.altervista.org
|
8
|
+
* E-mail: mailto:ragnettosoftware@gmail.com
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
a copy of this software and associated documentation files to deal in
|
12
|
+
the Software without restriction, including without limitation the
|
13
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense
|
14
|
+
and or sell copies of the Software, and to permit persons to whom the
|
15
|
+
Software is furnished to do so, subject to the following conditions.
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be
|
18
|
+
included in all copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND AND
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
23
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
24
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT
|
25
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
26
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
|
28
|
+
<b>Copyright (c) 2010 RAGNETTO (r) Software</b>
|
data/README
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= Ruby Conio 1.0
|
2
|
+
|
3
|
+
Author: Gabriele Secci
|
4
|
+
|
5
|
+
* http://rubyforge.org/projects/conio
|
6
|
+
* http://google.code.com/p/rubyconio
|
7
|
+
|
8
|
+
== DESCRIPTION
|
9
|
+
|
10
|
+
Ruby Conio 1.0 is a wrapper for Turbo C conio, used to create text user interfaces developed by Gabriele Secci.
|
11
|
+
|
12
|
+
The functions of "libconio.so" are implemented in C ANSI using the "libconio.a" library and "conio.h" header, available from the site: "http://conio.sourceforge.net".
|
13
|
+
Module "libconio.so" are compiled with mingw32-gcc from RDK (Ruby Development Kit).
|
14
|
+
|
15
|
+
For the bug or various problem, or source "libconio.c", please send me E-mail at:</i> mailto:ragnettosoftware@gmail.com
|
16
|
+
|
17
|
+
== INSTALL
|
18
|
+
|
19
|
+
GEM File:
|
20
|
+
* $ gem install conio
|
21
|
+
|
22
|
+
EXE File:
|
23
|
+
* Double click in the exe file and follow the installation instruction.
|
24
|
+
|
25
|
+
ZIP File:
|
26
|
+
* Extract the content from zip file and copy it in the gems folder of your Ruby interpreter.
|
27
|
+
|
28
|
+
== EXAMPLE
|
29
|
+
|
30
|
+
This is a simple example of conio module.
|
31
|
+
|
32
|
+
require "conio"
|
33
|
+
|
34
|
+
# Set the console title
|
35
|
+
settitle("Ruby Conio example...")
|
36
|
+
|
37
|
+
# Set the text color
|
38
|
+
textcolor(RED)
|
39
|
+
|
40
|
+
# Hide cursor
|
41
|
+
setcursortype(HIDE)
|
42
|
+
|
43
|
+
# Print message
|
44
|
+
print("Press ENTER key\n\n")
|
45
|
+
|
46
|
+
# Stop program while users press ENTER...
|
47
|
+
while getch() != 13
|
48
|
+
# nil
|
49
|
+
end
|
50
|
+
|
51
|
+
# Print message
|
52
|
+
print("OK! You are pressed ENTER key")
|
53
|
+
|
54
|
+
# Exit before 2 seconds
|
55
|
+
delay(2000)
|
56
|
+
|
57
|
+
For other examples see the "test" folder.
|
58
|
+
|
59
|
+
== DEVELOPER
|
60
|
+
|
61
|
+
* Author: Gabriele Secci
|
62
|
+
* Web: http://www.ragnetto.altervista.org
|
63
|
+
* E-mail: mailto:ragnettosoftware@gmail.com
|
64
|
+
|
65
|
+
== LICENSE
|
66
|
+
|
67
|
+
See LICENSE file.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Require ruby module
|
2
|
+
require "rubygems"
|
3
|
+
require "rake"
|
4
|
+
require "rake/clean"
|
5
|
+
require "rake/gempackagetask"
|
6
|
+
require "rake/rdoctask"
|
7
|
+
require "rake/testtask"
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = "conio"
|
11
|
+
s.version = "1.0"
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = ["README", "LICENSE"]
|
14
|
+
s.summary = "Ruby Conio 1.0 is wrapper for Turbo C conio, used to create text user interfaces developed by Gabriele Secci."
|
15
|
+
s.description = "Library Console I/O for Ruby"
|
16
|
+
s.author = "Gabriele Secci"
|
17
|
+
s.email = "ragnettosoftware@gmail.com"
|
18
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,test}/**/*")
|
19
|
+
s.require_path = "lib"
|
20
|
+
s.bindir = "bin"
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::GemPackageTask.new(spec) do |p|
|
24
|
+
p.gem_spec = spec
|
25
|
+
p.need_tar = false
|
26
|
+
p.need_zip = true
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
files =["README", "LICENSE", "lib/conio.rb"]
|
31
|
+
rdoc.rdoc_files.add(files)
|
32
|
+
rdoc.main = "README"
|
33
|
+
rdoc.title = "Ruby Conio"
|
34
|
+
rdoc.rdoc_dir = "rdoc"
|
35
|
+
rdoc.options << "--line-numbers"
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::TestTask.new do |t|
|
39
|
+
t.test_files = FileList["test/test.rb"]
|
40
|
+
end
|
data/lib/conio.rb
ADDED
@@ -0,0 +1,579 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Library Console I/O for Ruby
|
4
|
+
|
5
|
+
# *******************************************************
|
6
|
+
# * Conio *
|
7
|
+
# *******************************************************
|
8
|
+
# * Library Console I/O for Ruby *
|
9
|
+
# *******************************************************
|
10
|
+
# * Title: Conio *
|
11
|
+
# * Version: 1.0 *
|
12
|
+
# * Language: Ruby *
|
13
|
+
# * Source: conio.rb *
|
14
|
+
# *******************************************************
|
15
|
+
# * Author: Gabriele Secci *
|
16
|
+
# * Company: RAGNETTO (R) Software *
|
17
|
+
# * E-mail: ragnettosoftware@gmail.com *
|
18
|
+
# * Web: www.ragnetto.altervista.org *
|
19
|
+
# *******************************************************
|
20
|
+
# * Copyright (C) 2010 RAGNETTO Software *
|
21
|
+
# *******************************************************
|
22
|
+
|
23
|
+
# Require Dynamic Library [libconio.so]
|
24
|
+
require "libconio"
|
25
|
+
|
26
|
+
# Include Object Libconio
|
27
|
+
include Libconio
|
28
|
+
|
29
|
+
# ****************
|
30
|
+
# * Conio Module *
|
31
|
+
# ****************
|
32
|
+
|
33
|
+
module Conio
|
34
|
+
|
35
|
+
# ******************
|
36
|
+
# * Conio Costants *
|
37
|
+
# ******************
|
38
|
+
|
39
|
+
# Costant Color Value
|
40
|
+
BLACK = 0
|
41
|
+
|
42
|
+
# Costant Color Value
|
43
|
+
BLUE = 1
|
44
|
+
|
45
|
+
# Costant Color Value
|
46
|
+
GREEN = 2
|
47
|
+
|
48
|
+
# Costant Color Value
|
49
|
+
CYAN = 3
|
50
|
+
|
51
|
+
# Costant Color Value
|
52
|
+
RED = 4
|
53
|
+
|
54
|
+
# Costant Color Value
|
55
|
+
MAGENTA = 5
|
56
|
+
|
57
|
+
# Costant Color Value
|
58
|
+
BROWN = 6
|
59
|
+
|
60
|
+
# Costant Color Value
|
61
|
+
LIGHTGRAY = 7
|
62
|
+
|
63
|
+
# Costant Color Value
|
64
|
+
DARKGRAY = 8
|
65
|
+
|
66
|
+
# Costant Color Value
|
67
|
+
LIGHTBLUE = 9
|
68
|
+
|
69
|
+
# Costant Color Value
|
70
|
+
LIGHTGREEN = 10
|
71
|
+
|
72
|
+
# Costant Color Value
|
73
|
+
LIGHTCYAN = 11
|
74
|
+
|
75
|
+
# Costant Color Value
|
76
|
+
LIGHTRED = 12
|
77
|
+
|
78
|
+
# Costant Color Value
|
79
|
+
LIGHTMAGENTA = 13
|
80
|
+
|
81
|
+
# Costant Color Value
|
82
|
+
YELLOW = 14
|
83
|
+
|
84
|
+
# Costant Color Value
|
85
|
+
WHITE = 15
|
86
|
+
|
87
|
+
# Costant Info Value
|
88
|
+
ATTR = 0
|
89
|
+
|
90
|
+
# Costant Info Value
|
91
|
+
CX = 1
|
92
|
+
|
93
|
+
# Costant Info Value
|
94
|
+
CY = 2
|
95
|
+
|
96
|
+
# Costant Info Value
|
97
|
+
TOP = 3
|
98
|
+
|
99
|
+
# Costant Info Value
|
100
|
+
LEFT = 4
|
101
|
+
|
102
|
+
# Costant Info Value
|
103
|
+
RIGHT = 5
|
104
|
+
|
105
|
+
# Costant Info Value
|
106
|
+
BOTTOM = 6
|
107
|
+
|
108
|
+
# Costant Info Value
|
109
|
+
WIDTH = 7
|
110
|
+
|
111
|
+
# Costant Info Value
|
112
|
+
HEIGHT = 8
|
113
|
+
|
114
|
+
# Costant Info Value
|
115
|
+
MAXWIDTH = 9
|
116
|
+
|
117
|
+
# Costant Info Value
|
118
|
+
MAXHEIGHT = 10
|
119
|
+
|
120
|
+
# Costant Info Value
|
121
|
+
TOTALWIDTH = 11
|
122
|
+
|
123
|
+
# Costant Info Value
|
124
|
+
TOTALHEIGHT = 12
|
125
|
+
|
126
|
+
# Costant Text Info Value
|
127
|
+
ATTRIBUTE = 0
|
128
|
+
|
129
|
+
# Costant Text Info Value
|
130
|
+
NORMATTR = 1
|
131
|
+
|
132
|
+
# Costant Text Info Value
|
133
|
+
CURRMODE = 2
|
134
|
+
|
135
|
+
# Costant Text Info Value
|
136
|
+
CURX = 3
|
137
|
+
|
138
|
+
# Costant Text Info Value
|
139
|
+
CURY = 4
|
140
|
+
|
141
|
+
# Costant Text Info Value
|
142
|
+
SCREENWIDTH = 5
|
143
|
+
|
144
|
+
# Costant Text Info Value
|
145
|
+
SCREENHEIGHT = 6
|
146
|
+
|
147
|
+
# Costant Text Info Value
|
148
|
+
WINLEFT = 7
|
149
|
+
|
150
|
+
# Costant Text Info Value
|
151
|
+
WINTOP = 8
|
152
|
+
|
153
|
+
# Costant Text Info Value
|
154
|
+
WINRIGHT = 9
|
155
|
+
|
156
|
+
# Costant Text Info Value
|
157
|
+
WINBOTTOM = 10
|
158
|
+
|
159
|
+
# Costant Cursor Value
|
160
|
+
HIDE = 0
|
161
|
+
|
162
|
+
# Costant Cursor Value
|
163
|
+
NORMAL = 25
|
164
|
+
|
165
|
+
# Costant Cursor Value
|
166
|
+
SOLID = 100
|
167
|
+
|
168
|
+
# ***************************
|
169
|
+
# * Conio Library Functions *
|
170
|
+
# ***************************
|
171
|
+
|
172
|
+
# Reads a string of characters from the console and stores the string, and the string length, in the location string.
|
173
|
+
def cgets(lenght)
|
174
|
+
# Ruby Function cgets()
|
175
|
+
value = Libconio.ruby_cgets(lenght)
|
176
|
+
|
177
|
+
# Return value
|
178
|
+
return value
|
179
|
+
end
|
180
|
+
|
181
|
+
# Clears all characters from the cursor position to the end of the line within the string length, in the location string.
|
182
|
+
def clreol()
|
183
|
+
# Ruby Function clreol()
|
184
|
+
Libconio.ruby_clreol()
|
185
|
+
|
186
|
+
# Return nil
|
187
|
+
return nil
|
188
|
+
end
|
189
|
+
|
190
|
+
# Clears the current text window and places the cursor in the upper left hand corner.
|
191
|
+
def clrscr()
|
192
|
+
# Ruby Function clrscr()
|
193
|
+
Libconio.ruby_clrscr()
|
194
|
+
|
195
|
+
# Return nil
|
196
|
+
return nil
|
197
|
+
end
|
198
|
+
|
199
|
+
# Writes the null-terminated string text to the current text window. It does not append a newline character.
|
200
|
+
def cputs(text)
|
201
|
+
# Ruby Function cputs()
|
202
|
+
value = Libconio.ruby_cputs(text)
|
203
|
+
|
204
|
+
# Return text value
|
205
|
+
return value
|
206
|
+
end
|
207
|
+
|
208
|
+
# Crop the window console buffer size.
|
209
|
+
def crop()
|
210
|
+
# Ruby Function crop()
|
211
|
+
Libconio.ruby_crop()
|
212
|
+
|
213
|
+
# Return nil
|
214
|
+
return nil
|
215
|
+
end
|
216
|
+
|
217
|
+
# The time interval for which execution is to be suspended, in milliseconds.
|
218
|
+
def delay(milliseconds)
|
219
|
+
# Ruby Function delay()
|
220
|
+
Libconio.ruby_delay(milliseconds)
|
221
|
+
|
222
|
+
# Return nil
|
223
|
+
return nil
|
224
|
+
end
|
225
|
+
|
226
|
+
# Deletes the line containing the cursor and moves all lines below it a line up.
|
227
|
+
def delline()
|
228
|
+
# Ruby Function delline()
|
229
|
+
Libconio.ruby_delline()
|
230
|
+
|
231
|
+
# Return nil
|
232
|
+
return nil
|
233
|
+
end
|
234
|
+
|
235
|
+
# Write the specified number of consecutive characters, beginning at X and Y coordinates, with the value specified attribute.
|
236
|
+
def fill(character,forecolor, backcolor, number, x, y)
|
237
|
+
# Ruby Function fill()
|
238
|
+
Libconio.ruby_fill(character, forecolor, backcolor, number, x, y)
|
239
|
+
|
240
|
+
# Return nil
|
241
|
+
return nil
|
242
|
+
end
|
243
|
+
|
244
|
+
# Fills the specified number of consecutive attributes, beginning at X and Y coordinates, with the value specified attribute.
|
245
|
+
def fillattr(forecolor, backcolor, number, x, y)
|
246
|
+
# Ruby Function fillattr()
|
247
|
+
Libconio.ruby_fillattr(forecolor, backcolor, number, x, y)
|
248
|
+
|
249
|
+
# Return nil
|
250
|
+
return nil
|
251
|
+
end
|
252
|
+
|
253
|
+
# Write the specified number of consecutive characters, beginning at X and Y coordinates.
|
254
|
+
def fillchar(character, number, x, y)
|
255
|
+
# Ruby Function fillchar()
|
256
|
+
Libconio.ruby_fillchar(character, number, x, y)
|
257
|
+
|
258
|
+
# Return nil
|
259
|
+
return nil
|
260
|
+
end
|
261
|
+
|
262
|
+
# Write the specified number of consecutive characters, beginning at X and Y coordinates.
|
263
|
+
def fillcr(character, number, x, y)
|
264
|
+
# Ruby Function fillcr()
|
265
|
+
Libconio.ruby_fillcr(character, number, x, y)
|
266
|
+
|
267
|
+
# Return nil
|
268
|
+
return nil
|
269
|
+
end
|
270
|
+
|
271
|
+
# Get the contents with attributes of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
272
|
+
def get(left, top, right, bottom, buffer)
|
273
|
+
# Ruby Function get()
|
274
|
+
Libconio.ruby_get(left, top, right, bottom, buffer)
|
275
|
+
|
276
|
+
# Return nil
|
277
|
+
return nil
|
278
|
+
end
|
279
|
+
|
280
|
+
# Get the attributes of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
281
|
+
def getattrs(left, top, right, bottom, buffer)
|
282
|
+
# Ruby Function getattrs()
|
283
|
+
Libconio.ruby_getattrs(left, top, right, bottom, buffer)
|
284
|
+
|
285
|
+
# Return nil
|
286
|
+
return nil
|
287
|
+
end
|
288
|
+
|
289
|
+
# Reads a single character directly from the keyboard, without echoing to the screen.
|
290
|
+
def getch()
|
291
|
+
# Ruby Function getch()
|
292
|
+
value = Libconio.ruby_getch()
|
293
|
+
|
294
|
+
# Return character value
|
295
|
+
return value
|
296
|
+
end
|
297
|
+
|
298
|
+
# Get the contents of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
299
|
+
def getchars(left, top, right, bottom, buffer)
|
300
|
+
# Ruby Function getchars()
|
301
|
+
Libconio.ruby_getchars(left, top, right, bottom, buffer)
|
302
|
+
|
303
|
+
# Return nil
|
304
|
+
return nil
|
305
|
+
end
|
306
|
+
|
307
|
+
# Reads a single character from the keyboard and echoes it to the current text windows.
|
308
|
+
def getche()
|
309
|
+
# Ruby Function getche()
|
310
|
+
value = Libconio.ruby_getche()
|
311
|
+
|
312
|
+
# Return value
|
313
|
+
return value
|
314
|
+
end
|
315
|
+
|
316
|
+
# Gets video information.
|
317
|
+
def getinfo()
|
318
|
+
# Ruby Function getinfo()
|
319
|
+
value = Libconio.ruby_getinfo()
|
320
|
+
|
321
|
+
# Return value
|
322
|
+
return value
|
323
|
+
end
|
324
|
+
|
325
|
+
# Get the text of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
326
|
+
def gettext(left, top, right, bottom, buffer)
|
327
|
+
# Ruby Function gettext()
|
328
|
+
Libconio.ruby_gettext(left, top, right, bottom, buffer)
|
329
|
+
|
330
|
+
# Return nil
|
331
|
+
return nil
|
332
|
+
end
|
333
|
+
|
334
|
+
# Gets text mode video information.
|
335
|
+
def gettextinfo()
|
336
|
+
# Ruby Function gettextinfo()
|
337
|
+
value = Libconio.ruby_gettextinfo()
|
338
|
+
|
339
|
+
# Return value
|
340
|
+
return value
|
341
|
+
end
|
342
|
+
|
343
|
+
# Moves the cursor to the given position in the current text window.
|
344
|
+
def gotoxy(x, y)
|
345
|
+
# Ruby Function gotoxy()
|
346
|
+
Libconio.ruby_gotoxy(x, y)
|
347
|
+
|
348
|
+
# Return nil
|
349
|
+
return nil
|
350
|
+
end
|
351
|
+
|
352
|
+
# Inserts an empty line in the text window at the cursor position using the current text background color.
|
353
|
+
def insline()
|
354
|
+
# Ruby Function insline()
|
355
|
+
Libconio.ruby_insline()
|
356
|
+
|
357
|
+
# Return nil
|
358
|
+
return nil
|
359
|
+
end
|
360
|
+
|
361
|
+
# Checks to see if a keystroke is currently available.
|
362
|
+
def kbhit()
|
363
|
+
# Ruby Function kbhit()
|
364
|
+
value = Libconio.ruby_kbhit()
|
365
|
+
|
366
|
+
# Return value
|
367
|
+
return value
|
368
|
+
end
|
369
|
+
|
370
|
+
# Copies the contents of the onscreen rectangle defined by left, top, right, and bottom to a new rectangle of the same dimensions.
|
371
|
+
def movetext(left, top, right, bottom, newleft, newtop)
|
372
|
+
# Ruby Function movetext()
|
373
|
+
Libconio.ruby_movetext(left, top, right, bottom, newleft, newtop)
|
374
|
+
|
375
|
+
# Return nil
|
376
|
+
return nil
|
377
|
+
end
|
378
|
+
|
379
|
+
# Put the contents with attributes of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
380
|
+
def put(left, top, right, bottom, buffer)
|
381
|
+
# Ruby Function put()
|
382
|
+
Libconio.ruby_put(left, top, right, bottom, buffer)
|
383
|
+
|
384
|
+
# Return nil
|
385
|
+
return nil
|
386
|
+
end
|
387
|
+
|
388
|
+
# Put the attributes of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
389
|
+
def putattrs(left, top, right, bottom, buffer)
|
390
|
+
# Ruby Function putattrs()
|
391
|
+
Libconio.ruby_putattrs(left, top, right, bottom, buffer)
|
392
|
+
|
393
|
+
# Return nil
|
394
|
+
return nil
|
395
|
+
end
|
396
|
+
|
397
|
+
# Outputs the character to the current text window. It is a text-mode function that performs direct video output to the console.
|
398
|
+
def putch(character)
|
399
|
+
# Ruby Function putch()
|
400
|
+
value = Libconio.ruby_putch(character)
|
401
|
+
|
402
|
+
# Return value
|
403
|
+
return value
|
404
|
+
end
|
405
|
+
|
406
|
+
# Put the contents of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
407
|
+
def putchars(left, top, right, bottom, buffer)
|
408
|
+
# Ruby Function putchars()
|
409
|
+
Libconio.ruby_putchars(left, top, right, bottom, buffer)
|
410
|
+
|
411
|
+
# Return nil
|
412
|
+
return nil
|
413
|
+
end
|
414
|
+
|
415
|
+
# Put the text of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
|
416
|
+
def puttext(left, top, right, bottom, buffer)
|
417
|
+
# Ruby Function puttext()
|
418
|
+
Libconio.ruby_puttext(left, top, right, bottom, buffer)
|
419
|
+
|
420
|
+
# Return nil
|
421
|
+
return nil
|
422
|
+
end
|
423
|
+
|
424
|
+
# Resize buffer and window size.
|
425
|
+
def resize(width, height)
|
426
|
+
# Ruby Function resize()
|
427
|
+
Libconio.ruby_resize(width, height)
|
428
|
+
|
429
|
+
# Return nil
|
430
|
+
return nil
|
431
|
+
end
|
432
|
+
|
433
|
+
# The console window displays a portion of the active screen buffer.
|
434
|
+
def scroll(left, top, right, bottom, newleft, newtop)
|
435
|
+
# Ruby Function scroll()
|
436
|
+
Libconio.ruby_scroll(left, top, right, bottom, newleft, newtop)
|
437
|
+
|
438
|
+
# Return nil
|
439
|
+
return nil
|
440
|
+
end
|
441
|
+
|
442
|
+
# Scroll up the text in current window text.
|
443
|
+
def scrollup(left, top, right, bottom)
|
444
|
+
# Ruby Function scrollup()
|
445
|
+
Libconio.ruby_scrollup(left, top, right, bottom)
|
446
|
+
|
447
|
+
# Return nil
|
448
|
+
return nil
|
449
|
+
end
|
450
|
+
|
451
|
+
# Scroll down the text in current window text.
|
452
|
+
def scrolldown(left, top, right, bottom)
|
453
|
+
# Ruby Function scrolldown()
|
454
|
+
Libconio.ruby_scrolldown(left, top, right, bottom)
|
455
|
+
|
456
|
+
# Return nil
|
457
|
+
return nil
|
458
|
+
end
|
459
|
+
|
460
|
+
# Scroll left the text in current window text.
|
461
|
+
def scrollleft(left, top, right, bottom)
|
462
|
+
# Ruby Function scrollleft()
|
463
|
+
Libconio.ruby_scrollleft(left, top, right, bottom)
|
464
|
+
|
465
|
+
# Return nil
|
466
|
+
return nil
|
467
|
+
end
|
468
|
+
|
469
|
+
# Scroll right the text in current window text.
|
470
|
+
def scrollright(left, top, right, bottom)
|
471
|
+
# Ruby Function scrollright()
|
472
|
+
Libconio.ruby_scrollright(left, top, right, bottom)
|
473
|
+
|
474
|
+
# Return nil
|
475
|
+
return nil
|
476
|
+
end
|
477
|
+
|
478
|
+
# Define a window buffer size.
|
479
|
+
def setbuffer(width, height)
|
480
|
+
# Ruby Function setbuffer()
|
481
|
+
Libconio.ruby_setbuffer(width, height)
|
482
|
+
|
483
|
+
# Return nil
|
484
|
+
return nil
|
485
|
+
end
|
486
|
+
|
487
|
+
# Sets the cursor type in range 0 (hide cursor) to 100 (solid block cursor).
|
488
|
+
def setcursortype(cursor)
|
489
|
+
# Ruby Function setcursortype()
|
490
|
+
Libconio.ruby_setcursortype(cursor)
|
491
|
+
|
492
|
+
# Return nil
|
493
|
+
return nil
|
494
|
+
end
|
495
|
+
|
496
|
+
# Change the console window title.
|
497
|
+
def settitle(title)
|
498
|
+
# Ruby Function settitle()
|
499
|
+
Libconio.ruby_settitle(title)
|
500
|
+
|
501
|
+
# Return nil
|
502
|
+
return nil
|
503
|
+
end
|
504
|
+
|
505
|
+
# Defines a text window onscreen. If the coordinates are in any way invalid, the call to window is ignored.
|
506
|
+
def setwindow(left, top, right, bottom)
|
507
|
+
# Ruby Function setwindow()
|
508
|
+
Libconio.ruby_setwindow(left, top, right, bottom)
|
509
|
+
|
510
|
+
# Return nil
|
511
|
+
return nil
|
512
|
+
end
|
513
|
+
|
514
|
+
# The time interval for which execution is to be suspended, in seconds.
|
515
|
+
def sleep(seconds)
|
516
|
+
# Ruby Function sleep()
|
517
|
+
Libconio.ruby_sleep(seconds)
|
518
|
+
|
519
|
+
# Return nil
|
520
|
+
return nil
|
521
|
+
end
|
522
|
+
|
523
|
+
# Selects the background character color.
|
524
|
+
def textbackground(color)
|
525
|
+
# Ruby Function textbackground()
|
526
|
+
Libconio.ruby_textbackground(color)
|
527
|
+
|
528
|
+
# Return nil
|
529
|
+
return nil
|
530
|
+
end
|
531
|
+
|
532
|
+
# Selects the foreground character color.
|
533
|
+
def textcolor(color)
|
534
|
+
# Ruby Function textcolor()
|
535
|
+
Libconio.ruby_textcolor(color)
|
536
|
+
|
537
|
+
# Return nil
|
538
|
+
return nil
|
539
|
+
end
|
540
|
+
|
541
|
+
# Pushes the character ch back to the console, causing ch to be the next character read.
|
542
|
+
def ungetch(character)
|
543
|
+
# Ruby Function ungetch()
|
544
|
+
value = Libconio.ruby_ungetch(character)
|
545
|
+
|
546
|
+
# Return value
|
547
|
+
return value
|
548
|
+
end
|
549
|
+
|
550
|
+
# Returns the X coordinate of the current cursor position (within the current text window).
|
551
|
+
def wherex()
|
552
|
+
# Ruby Function wherex()
|
553
|
+
value = Libconio.ruby_wherex()
|
554
|
+
|
555
|
+
# Return value
|
556
|
+
return value
|
557
|
+
end
|
558
|
+
|
559
|
+
# Copies the value of x coordinate and y coordinate of the cursor location to the variables whose address is specified in the arguments column and row.
|
560
|
+
def wherexy(x, y)
|
561
|
+
# Ruby Function wherex()
|
562
|
+
Libconio.ruby_wherexy(x, y)
|
563
|
+
|
564
|
+
# Return nil
|
565
|
+
return nil
|
566
|
+
end
|
567
|
+
|
568
|
+
# Returns the Y coordinate of the current cursor position (within the current text window).
|
569
|
+
def wherey()
|
570
|
+
# Ruby Function wherey()
|
571
|
+
value = Libconio.ruby_wherey()
|
572
|
+
|
573
|
+
# Return value
|
574
|
+
return value
|
575
|
+
end
|
576
|
+
|
577
|
+
end
|
578
|
+
|
579
|
+
# End of file
|
data/lib/libconio.so
ADDED
Binary file
|
data/test/test.rb
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
# Require Library [conio.rb]
|
2
|
+
require "conio"
|
3
|
+
|
4
|
+
include Conio
|
5
|
+
|
6
|
+
# Globals variables
|
7
|
+
$index = nil
|
8
|
+
$table = nil
|
9
|
+
|
10
|
+
# *****************
|
11
|
+
# * main function *
|
12
|
+
# *****************
|
13
|
+
|
14
|
+
def main()
|
15
|
+
# Set console title
|
16
|
+
Conio.settitle("Ruby Conio 1.0")
|
17
|
+
|
18
|
+
# Set console size
|
19
|
+
Conio.resize(80, 30)
|
20
|
+
|
21
|
+
# Set cursor
|
22
|
+
Conio.setcursortype(HIDE)
|
23
|
+
|
24
|
+
# Call def display()
|
25
|
+
display()
|
26
|
+
end
|
27
|
+
|
28
|
+
# *********************
|
29
|
+
# * Program functions *
|
30
|
+
# *********************
|
31
|
+
|
32
|
+
def display()
|
33
|
+
# Print text console
|
34
|
+
write("Ruby Conio 1.0", 1, 0)
|
35
|
+
write("Author: Gabriele Secci", 57, 0)
|
36
|
+
write("COPYRIGHT \xb8 2010 RAGNETTO \xa9 Software - All Rights Reserved", 11, 29)
|
37
|
+
|
38
|
+
# Fill attribute of text console
|
39
|
+
Conio.fillattr(WHITE, RED, 80, 0, 0)
|
40
|
+
Conio.fillattr(WHITE, RED, 80, 0, 29)
|
41
|
+
|
42
|
+
# Set text and background color
|
43
|
+
Conio.textbackground(BLACK)
|
44
|
+
Conio.textcolor(RED)
|
45
|
+
|
46
|
+
# Print text console
|
47
|
+
write("\xda", 1, 1)
|
48
|
+
write("\xbf", 46, 1)
|
49
|
+
write("\xb3", 1, 2)
|
50
|
+
write("\xb3", 46, 2)
|
51
|
+
write("\xc0", 1, 3)
|
52
|
+
write("\xd9", 46, 3)
|
53
|
+
|
54
|
+
# Fill attribute of text console
|
55
|
+
Conio.fill(196, RED, BLACK, 44, 2, 1)
|
56
|
+
Conio.fill(196, RED, BLACK, 44, 2, 3)
|
57
|
+
|
58
|
+
# Print text console
|
59
|
+
write("\xda", 1, 4)
|
60
|
+
write("\xbf", 46, 4)
|
61
|
+
|
62
|
+
for i in 5 .. 24 do
|
63
|
+
write("\xb3", 1, i)
|
64
|
+
write("\xb3", 46, i)
|
65
|
+
end
|
66
|
+
|
67
|
+
write("\xc0", 1, 25)
|
68
|
+
write("\xd9", 46, 25)
|
69
|
+
|
70
|
+
# Fill attribute of text console
|
71
|
+
Conio.fill(196, RED, BLACK, 44, 2, 4)
|
72
|
+
Conio.fill(196, RED, BLACK, 44, 2, 25)
|
73
|
+
|
74
|
+
# Print text console
|
75
|
+
write("\xda", 48, 1)
|
76
|
+
write("\xbf", 78, 1)
|
77
|
+
write("\xb3", 48, 2)
|
78
|
+
write("\xb3", 78, 2)
|
79
|
+
write("\xc0", 48, 3)
|
80
|
+
write("\xd9", 78, 3)
|
81
|
+
write("\xda", 48, 4)
|
82
|
+
write("\xbf", 78, 4)
|
83
|
+
|
84
|
+
for i in 5 .. 27 do
|
85
|
+
write("\xb3", 48, i)
|
86
|
+
write("\xb3", 76, i)
|
87
|
+
write("\xb3", 78, i)
|
88
|
+
end
|
89
|
+
|
90
|
+
write("\xc0", 48, 28)
|
91
|
+
write("\xd9", 78, 28)
|
92
|
+
|
93
|
+
# Fill attribute of text console
|
94
|
+
Conio.fill(196, RED, BLACK, 29, 49, 1)
|
95
|
+
Conio.fill(196, RED, BLACK, 29, 49, 3)
|
96
|
+
Conio.fill(196, RED, BLACK, 29, 49, 4)
|
97
|
+
Conio.fill(196, RED, BLACK, 29, 49, 28)
|
98
|
+
|
99
|
+
# Print text console
|
100
|
+
write("\xc2", 76, 4)
|
101
|
+
write("\xc1", 76, 28)
|
102
|
+
write("\xda", 1, 26)
|
103
|
+
write("\xbf", 46, 26)
|
104
|
+
write("\xb3", 1, 27)
|
105
|
+
write("\xb3", 46, 27)
|
106
|
+
write("\xc0", 1, 28)
|
107
|
+
write("\xd9", 46, 28)
|
108
|
+
|
109
|
+
# Fill attribute of text console
|
110
|
+
Conio.fill(196, RED, BLACK, 44, 2, 26)
|
111
|
+
Conio.fill(196, RED, BLACK, 44, 2, 28)
|
112
|
+
|
113
|
+
# Set text and background color
|
114
|
+
Conio.textbackground(BLACK)
|
115
|
+
Conio.textcolor(WHITE)
|
116
|
+
|
117
|
+
# Print text console
|
118
|
+
write("Conio 1.0 is wrapper for Turbo C conio", 5, 2)
|
119
|
+
write("FUNCTION", 60, 2)
|
120
|
+
write("Project: Ruby Conio", 3, 5)
|
121
|
+
write("Version: 1.0", 3, 6)
|
122
|
+
write("Language: Ruby 1.9", 3, 7)
|
123
|
+
write("License: GNU GPL", 3, 8)
|
124
|
+
write("", 3, 9)
|
125
|
+
write("Module: conio.rb", 3, 10)
|
126
|
+
write("Extension: libconio.so", 3, 11)
|
127
|
+
write("", 3, 12)
|
128
|
+
write("Author: Gabriele Secci", 3, 13)
|
129
|
+
write("Company: RAGNETTO Software", 3, 14)
|
130
|
+
write("E-Mail: ragnettosoftware@gmail.com", 3, 15)
|
131
|
+
write("Web: www.ragnetto.altervista.org", 3, 16)
|
132
|
+
write("", 3, 16)
|
133
|
+
write("ESC: Close \x18: Scroll Up \x19: Scroll Down", 3, 27)
|
134
|
+
|
135
|
+
# Call function functions()
|
136
|
+
functions()
|
137
|
+
end
|
138
|
+
|
139
|
+
def functions()
|
140
|
+
# Creating new table
|
141
|
+
$table = Array.new()
|
142
|
+
|
143
|
+
# Populate new table with functions of library Conio
|
144
|
+
$table[0] = "cgets(len) "
|
145
|
+
$table[1] = "clreol() "
|
146
|
+
$table[2] = "clrscr() "
|
147
|
+
$table[3] = "cputs(txt) "
|
148
|
+
$table[4] = "crop() "
|
149
|
+
$table[5] = "delay(ms) "
|
150
|
+
$table[6] = "delline() "
|
151
|
+
$table[7] = "fill(ch, fc, bc, n, x, y) "
|
152
|
+
$table[8] = "fillattr(fc, bc, n, x, y) "
|
153
|
+
$table[9] = "fillchar(ch, n, x, y) "
|
154
|
+
$table[10] = "fillcr(ch, n, x, y) "
|
155
|
+
$table[11] = "get(l, t, r, b, buf) "
|
156
|
+
$table[12] = "getattrs(l, t, r, b, buf) "
|
157
|
+
$table[13] = "getch() "
|
158
|
+
$table[14] = "getchars(l, t, r, b, buf) "
|
159
|
+
$table[15] = "getche() "
|
160
|
+
$table[16] = "getinfo() "
|
161
|
+
$table[17] = "gettext(l, t, r, b, buf) "
|
162
|
+
$table[18] = "gettextinfo() "
|
163
|
+
$table[19] = "gotoxy(x, y) "
|
164
|
+
$table[20] = "insline() "
|
165
|
+
$table[21] = "kbhit() "
|
166
|
+
$table[22] = "movetext(l, t, r, b, l, t)"
|
167
|
+
$table[23] = "put(l, t, r, b, buf) "
|
168
|
+
$table[24] = "putattrs(l, t, r, b, buf) "
|
169
|
+
$table[25] = "putch(ch) "
|
170
|
+
$table[26] = "putchars(l, t, r, b, buf) "
|
171
|
+
$table[27] = "puttext(l, t, r, b, buf) "
|
172
|
+
$table[28] = "resize() "
|
173
|
+
$table[29] = "scroll(l, t, r, b, l, t) "
|
174
|
+
$table[30] = "scrollup(l, t, r, b) "
|
175
|
+
$table[31] = "scrolldown(l, t, r, b) "
|
176
|
+
$table[32] = "scrollleft(l, t, r, b) "
|
177
|
+
$table[33] = "scrollright(l, t, r, b) "
|
178
|
+
$table[34] = "setbuffer(w, h) "
|
179
|
+
$table[35] = "setcursortype(cur) "
|
180
|
+
$table[36] = "settitle(tl) "
|
181
|
+
$table[37] = "setwindow(l, t, r, b) "
|
182
|
+
$table[38] = "sleep(s) "
|
183
|
+
$table[39] = "textbackground(bc) "
|
184
|
+
$table[40] = "textcolor(fc "
|
185
|
+
$table[41] = "ungetch(ch) "
|
186
|
+
$table[42] = "wherex() "
|
187
|
+
$table[43] = "wherexy(x, y) "
|
188
|
+
$table[44] = "wherey() "
|
189
|
+
|
190
|
+
# Set global variable index equal to 0
|
191
|
+
$index = 0
|
192
|
+
|
193
|
+
# Call function putter()
|
194
|
+
putter()
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
def putter()
|
199
|
+
|
200
|
+
# Verify global variable index value
|
201
|
+
if $index < 0 then
|
202
|
+
# Set global variable index equal to 0
|
203
|
+
$index = 0
|
204
|
+
elsif $index > 22 then
|
205
|
+
# Set global variable index equal to 22
|
206
|
+
$index = 22
|
207
|
+
else
|
208
|
+
# Get index
|
209
|
+
end
|
210
|
+
|
211
|
+
# Declare and initialize local variables limit and stop
|
212
|
+
limit = 5
|
213
|
+
stop = 22
|
214
|
+
|
215
|
+
# Cicle for print text functions
|
216
|
+
for i in $index .. $index + stop do
|
217
|
+
# Print text functions in the console
|
218
|
+
write($table[i], 50, limit)
|
219
|
+
|
220
|
+
# Verify the position of the cursor
|
221
|
+
if wherey() - 5 == $index then
|
222
|
+
# Print text console
|
223
|
+
write("\xdb", 77, limit)
|
224
|
+
else
|
225
|
+
# Print text console
|
226
|
+
write("\xb0", 77, limit)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Increment local varible limit
|
230
|
+
limit += 1
|
231
|
+
end
|
232
|
+
|
233
|
+
# Call function press()
|
234
|
+
press()
|
235
|
+
end
|
236
|
+
|
237
|
+
def move()
|
238
|
+
# Declare and initialize local variables key
|
239
|
+
key = Conio.getch()
|
240
|
+
|
241
|
+
# Verify local variable key value
|
242
|
+
if key == 80 then
|
243
|
+
# Set local variable index increment of 1
|
244
|
+
$index += 1
|
245
|
+
elsif key == 72 then
|
246
|
+
# Set local variable index decrement of 1
|
247
|
+
$index -=1
|
248
|
+
end
|
249
|
+
|
250
|
+
# Call function putter()
|
251
|
+
putter()
|
252
|
+
end
|
253
|
+
|
254
|
+
def exit(key)
|
255
|
+
# Verify parameter key value
|
256
|
+
if key == 27 then
|
257
|
+
# Quit program
|
258
|
+
Kernel.exit()
|
259
|
+
else
|
260
|
+
# Call function press()
|
261
|
+
press()
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# *********************
|
266
|
+
# * Service functions *
|
267
|
+
# *********************
|
268
|
+
|
269
|
+
def write(text, x, y)
|
270
|
+
# Set cursor position
|
271
|
+
Conio.gotoxy(x, y)
|
272
|
+
|
273
|
+
# Write string text
|
274
|
+
print(text)
|
275
|
+
end
|
276
|
+
|
277
|
+
def press()
|
278
|
+
# Declare and initialize local variables key
|
279
|
+
key = Conio.getch()
|
280
|
+
|
281
|
+
# Verify local variable key value equal to 224
|
282
|
+
while key != 224
|
283
|
+
# Call function exit()
|
284
|
+
exit(key)
|
285
|
+
|
286
|
+
# Exit cicle while
|
287
|
+
break
|
288
|
+
end
|
289
|
+
|
290
|
+
# Call function move()
|
291
|
+
move()
|
292
|
+
end
|
293
|
+
|
294
|
+
# **********************
|
295
|
+
# * Call main function *
|
296
|
+
# **********************
|
297
|
+
|
298
|
+
main()
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Gabriele Secci
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-07-17 00:00:00 +02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Library Console I/O for Ruby
|
21
|
+
email: ragnettosoftware@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files:
|
27
|
+
- README
|
28
|
+
- LICENSE
|
29
|
+
files:
|
30
|
+
- LICENSE
|
31
|
+
- README
|
32
|
+
- Rakefile
|
33
|
+
- lib/conio.rb
|
34
|
+
- lib/libconio.so
|
35
|
+
- test/test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage:
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Ruby Conio 1.0 is wrapper for Turbo C conio, used to create text user interfaces developed by Gabriele Secci.
|
66
|
+
test_files: []
|
67
|
+
|