conio 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/LICENSE +1 -1
  2. data/README +51 -33
  3. data/Rakefile +40 -40
  4. data/ext/libconio.c +1009 -0
  5. data/lib/conio.rb +392 -407
  6. data/lib/libconio.so +0 -0
  7. data/test/test.rb +31 -283
  8. metadata +10 -5
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- = Ruby Conio 1.0
2
+ = Ruby Conio 1.1.0
3
3
 
4
4
  LICENSE
5
5
 
data/README CHANGED
@@ -1,18 +1,19 @@
1
- = Ruby Conio 1.0
1
+ = Ruby Conio 1.1.0
2
2
 
3
3
  Author: Gabriele Secci
4
4
 
5
5
  * http://rubyforge.org/projects/conio
6
+ * http://rubygems.org/gems/conio
6
7
  * http://google.code.com/p/rubyconio
7
8
 
8
9
  == DESCRIPTION
9
10
 
10
- Ruby Conio 1.0 is a wrapper for Turbo C conio, used to create text user interfaces developed by Gabriele Secci.
11
+ Ruby Conio 1.1.0 is a wrapper for Turbo C conio, used to create text user interfaces developed by Gabriele Secci.
11
12
 
12
13
  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
+ Module "libconio.so" is compiled with mingw32-gcc.
14
15
 
15
- For the bug or various problem, or source "libconio.c", please send me E-mail at:</i> mailto:ragnettosoftware@gmail.com
16
+ For the bug or various problem, please send me E-mail at:</i> mailto:ragnettosoftware@gmail.com
16
17
 
17
18
  == INSTALL
18
19
 
@@ -22,43 +23,60 @@ GEM File:
22
23
  EXE File:
23
24
  * Double click in the exe file and follow the installation instruction.
24
25
 
25
- ZIP File:
26
- * Extract the content from zip file and copy it in the gems folder of your Ruby interpreter.
27
-
28
26
  == EXAMPLE
29
27
 
30
28
  This is a simple example of conio module.
31
29
 
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)
30
+ require "conio"
31
+
32
+ # Set the console title
33
+ Conio.settitle("Ruby Conio 1.1.0 [test.rb]")
34
+
35
+ # Set the console window and buffer size
36
+ Conio.resize(80, 30)
37
+
38
+ # Hide cursor
39
+ Conio.setcursortype(Conio::CURSOR_HIDE)
40
+
41
+ # Put name module
42
+ Conio.write("Ruby Conio 1.1.0", 1, 0)
43
+
44
+ # Put name script
45
+ Conio.write("test.rb", 72, 0)
46
+
47
+ # Select cursor position
48
+ Conio.gotoxy(20, 29)
49
+
50
+ # Put copyright
51
+ print("Copyright \xa9 2010 RAGNETTO \xb8 Software")
52
+
53
+ # Put text attribute
54
+ Conio.fillattr(Conio::COLOR_WHITE, Conio::COLOR_RED, 80, 0, 0)
55
+ Conio.fillattr(Conio::COLOR_WHITE, Conio::COLOR_RED, 80, 0, 29)
56
+
57
+ # Print message
58
+ Conio.write("Press F1 to exit...", 1, 3)
59
+
60
+ # Stop program while users press F1...
61
+ while Conio.getkey() != Conio::KEY_F1
62
+ # nil
63
+ Conio.getkey()
64
+ end
65
+
66
+ # Count exit time
67
+ for index in (-4..-1) do
68
+ # Print message
69
+ Conio.write("Program exit in 4 seconds: #{index}", 1, 27)
70
+
71
+ # Exit before 4 seconds
72
+ Conio.sleep(1)
73
+ end
56
74
 
57
- For other examples see the "test" folder.
75
+ Show this code in test folder [test.rb]
58
76
 
59
77
  == DEVELOPER
60
78
 
61
- * Author: Gabriele Secci
79
+ * Author: Gabriele Secci - RAGNETTO Software
62
80
  * Web: http://www.ragnetto.altervista.org
63
81
  * E-mail: mailto:ragnettosoftware@gmail.com
64
82
 
data/Rakefile CHANGED
@@ -1,40 +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
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+
8
+ spec = Gem::Specification.new do |s|
9
+ s.name = 'conio'
10
+ s.version = '1.1.0'
11
+ s.has_rdoc = true
12
+ s.extra_rdoc_files = ['README', 'LICENSE', 'ext/libconio.c']
13
+ s.summary = 'Ruby Conio is a wrapper for Turbo C conio.'
14
+ s.description = s.summary
15
+ s.author = 'Gabriele Secci'
16
+ s.email = 'ragnettosoftware@gmail.com'
17
+ # s.executables = ['your_executable_here']
18
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{ext,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 = true
26
+ p.need_zip = true
27
+ end
28
+
29
+ Rake::RDocTask.new do |rdoc|
30
+ files =['README', 'LICENSE', 'lib/conio.rb', 'ext/libconio.c']
31
+ rdoc.rdoc_files.add(files)
32
+ rdoc.main = "README"
33
+ rdoc.title = "Ruby Conio 1.1.0"
34
+ rdoc.rdoc_dir = 'doc'
35
+ rdoc.options << '--line-numbers'
36
+ end
37
+
38
+ Rake::TestTask.new do |t|
39
+ t.test_files = FileList['test/test.rb']
40
+ end
@@ -0,0 +1,1009 @@
1
+ /*
2
+ *******************************************************
3
+ * Conio *
4
+ *******************************************************
5
+ * Library Console I/O for Ruby *
6
+ *******************************************************
7
+ * Title: Conio *
8
+ * Version: 1.0 *
9
+ * Language: C *
10
+ * Source: libconio.c *
11
+ *******************************************************
12
+ * Author: Gabriele Secci *
13
+ * Company: RAGNETTO (R) Software *
14
+ * E-mail: ragnettosoftware@gmail.com *
15
+ * Web: www.ragnetto.altervista.org *
16
+ *******************************************************
17
+ * Copyright (C) 2010 RAGNETTO Software *
18
+ *******************************************************
19
+ */
20
+
21
+ // C Headers
22
+ #include <conio.h>
23
+ #include <stdio.h>
24
+
25
+ // Ruby headers
26
+ #include "ruby.h"
27
+
28
+ // declaration of Libconio Library
29
+ VALUE Libconio = Qnil;
30
+
31
+ // ***************************
32
+ // * Conio Library Functions *
33
+ // ***************************
34
+
35
+ /*
36
+ * call-seq:
37
+ * clreol() -> nil
38
+ *
39
+ * Clears all characters from the cursor position to the end of the
40
+ * line within the string length, in the location string.
41
+ */
42
+ VALUE method_clreol(VALUE self)
43
+ {
44
+ // Native function clreol()
45
+ clreol();
46
+
47
+ // Return NULL value
48
+ return Qnil;
49
+ }
50
+
51
+ /*
52
+ * call-seq:
53
+ * clrscr() -> nil
54
+ *
55
+ * Clears the current text window and places the cursor in the
56
+ * upper left hand corner at position 1, 1.
57
+ */
58
+ VALUE method_clrscr(VALUE self)
59
+ {
60
+ // Native function clrscr()
61
+ clrscr();
62
+
63
+ // Return NULL value
64
+ return Qnil;
65
+ }
66
+
67
+ /*
68
+ * call-seq:
69
+ * cputs(text) -> string
70
+ *
71
+ * Writes the null-terminated string text to the current text window.
72
+ */
73
+ VALUE method_cputs(VALUE self, VALUE string_text)
74
+ {
75
+ // Ruby conversion string
76
+ const char * text = StringValuePtr(string_text);
77
+
78
+ // Native function cputs()
79
+ cputs(text);
80
+
81
+ // Return value text
82
+ return rb_str_new2(text);
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * crop() -> nil
88
+ *
89
+ * Crop the window console buffer size.
90
+ */
91
+ VALUE method_crop(VALUE self)
92
+ {
93
+ // Native function crop()
94
+ con_crop();
95
+
96
+ // Return NULL value
97
+ return Qnil;
98
+ }
99
+
100
+ /*
101
+ * call-seq:
102
+ * delay(milliseconds) -> nil
103
+ *
104
+ * The time interval for which execution is to be suspended, in milliseconds.
105
+ */
106
+ VALUE method_delay(VALUE self, VALUE int_milliseconds)
107
+ {
108
+ // Ruby conversion long
109
+ int milliseconds = NUM2LONG(int_milliseconds);
110
+
111
+ // Native function delay()
112
+ delay(milliseconds);
113
+
114
+ // Return NULL value
115
+ return Qnil;
116
+ }
117
+
118
+ /*
119
+ * call-seq:
120
+ * delline() -> nil
121
+ *
122
+ * Deletes the line containing the cursor and moves all lines below it a line up.
123
+ */
124
+ VALUE method_delline(VALUE self)
125
+ {
126
+ // Native function delline()
127
+ delline();
128
+
129
+ // Return NULL value
130
+ return Qnil;
131
+ }
132
+
133
+ /*
134
+ * call-seq:
135
+ * fill(character, forecolor, backcolor, number, x, y) -> nil
136
+ *
137
+ * Write the specified number of consecutive characters, beginning at
138
+ * X and Y coordinates, with the value specified attribute.
139
+ */
140
+ VALUE method_fill(VALUE self, VALUE int_character, VALUE int_forecolor, VALUE int_backcolor, VALUE int_number, VALUE int_x, VALUE int_y)
141
+ {
142
+ // Ruby conversion integer
143
+ int character = NUM2INT(int_character);
144
+ int forecolor = NUM2INT(int_forecolor);
145
+ int backcolor = NUM2INT(int_backcolor);
146
+ int number = NUM2INT(int_number);
147
+ int x = NUM2INT(int_x);
148
+ int y = NUM2INT(int_y);
149
+
150
+ // Native function fill()
151
+ con_fill(character, forecolor, backcolor, number, x, y);
152
+
153
+ // Return NULL value
154
+ return Qnil;
155
+ }
156
+
157
+ /*
158
+ * call-seq:
159
+ * fillattr(forecolor, backcolor, number, x, y) -> nil
160
+ *
161
+ * Fills the specified number of consecutive attributes, beginning at
162
+ * X and Y coordinates, with the value specified attribute.
163
+ */
164
+ VALUE method_fillattr(VALUE self, VALUE int_forecolor, VALUE int_backcolor, VALUE int_number, VALUE int_x, VALUE int_y)
165
+ {
166
+ // Ruby conversion integer
167
+ int forecolor = NUM2INT(int_forecolor);
168
+ int backcolor = NUM2INT(int_backcolor);
169
+ int number = NUM2INT(int_number);
170
+ int x = NUM2INT(int_x);
171
+ int y = NUM2INT(int_y);
172
+
173
+ // Native function fillattr()
174
+ con_fillattr(forecolor, backcolor, number, x, y);
175
+
176
+ // Return NULL value
177
+ return Qnil;
178
+ }
179
+
180
+ /*
181
+ * call-seq:
182
+ * fillchar(character, number, x, y) -> nil
183
+ *
184
+ * Write the specified number of consecutive characters, beginning at X and Y coordinates.
185
+ */
186
+ VALUE method_fillchar(VALUE self, VALUE int_character, VALUE int_number, VALUE int_x, VALUE int_y)
187
+ {
188
+ // Ruby conversion integer
189
+ int character = NUM2INT(int_character);
190
+ int number = NUM2INT(int_number);
191
+ int x = NUM2INT(int_x);
192
+ int y = NUM2INT(int_y);
193
+
194
+ // Native function fillchar()
195
+ con_fillchar(character, number, x, y);
196
+
197
+ // Return NULL value
198
+ return Qnil;
199
+ }
200
+
201
+ /*
202
+ * call-seq:
203
+ * fillcr(character, number, x, y) -> nil
204
+ *
205
+ * Write the specified number of consecutive characters, beginning at X and Y coordinates.
206
+ */
207
+ VALUE method_fillcr(VALUE self, VALUE int_character, VALUE int_number, VALUE int_x, VALUE int_y)
208
+ {
209
+ // Ruby conversion integer
210
+ int character = NUM2INT(int_character);
211
+ int number = NUM2INT(int_number);
212
+ int x = NUM2INT(int_x);
213
+ int y = NUM2INT(int_y);
214
+
215
+ // Native function fillcr()
216
+ con_fillcr(character, number, x, y);
217
+
218
+ // Return NULL value
219
+ return Qnil;
220
+ }
221
+
222
+ /*
223
+ * call-seq:
224
+ * get(left, top, right, bottom, buffer) -> nil
225
+ *
226
+ * Get the contents with attributes of the memory area source out to the
227
+ * onscreen rectangle defined by left, top, right and bottom.
228
+ */
229
+ VALUE method_get(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
230
+ {
231
+ // Ruby conversion integer
232
+ int left = NUM2INT(int_left);
233
+ int top = NUM2INT(int_top);
234
+ int right = NUM2INT(int_right);
235
+ int bottom = NUM2INT(int_bottom);
236
+ int buffer = NUM2INT(int_buffer);
237
+
238
+ // Declare variable dimension
239
+ int dimension[buffer];
240
+
241
+ // Native function get()
242
+ con_get(left, top, right, bottom, dimension);
243
+
244
+ // Return NULL value
245
+ return Qnil;
246
+ }
247
+
248
+ /*
249
+ * call-seq:
250
+ * getattrs(left, top, right, bottom, buffer) -> nil
251
+ *
252
+ * Get the attributes of the memory area source out to the onscreen
253
+ * rectangle defined by left, top, right and bottom.
254
+ */
255
+ VALUE method_getattrs(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
256
+ {
257
+ // Ruby conversion integer
258
+ int left = NUM2INT(int_left);
259
+ int top = NUM2INT(int_top);
260
+ int right = NUM2INT(int_right);
261
+ int bottom = NUM2INT(int_bottom);
262
+ int buffer = NUM2INT(int_buffer);
263
+
264
+ // Declare variable dimension
265
+ int dimension[buffer];
266
+
267
+ // Native function getattrs()
268
+ con_getattrs(left, top, right, bottom, dimension);
269
+
270
+ // Return NULL value
271
+ return Qnil;
272
+ }
273
+
274
+ /*
275
+ * call-seq:
276
+ * getch() -> number
277
+ *
278
+ * Reads a single character directly from the keyboard, without echoing to the screen.
279
+ */
280
+ VALUE method_getch(VALUE self)
281
+ {
282
+ // Native function getch()
283
+ int character = getch();
284
+
285
+ // Return value character
286
+ return INT2NUM(character);
287
+ }
288
+
289
+ /*
290
+ * call-seq:
291
+ * getchars(left, top, right, bottom, buffer) -> nil
292
+ *
293
+ * Get the contents of the memory area source out to the onscreen rectangle defined by left, top, right and bottom.
294
+ */
295
+ VALUE method_getchars(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
296
+ {
297
+ // Ruby conversion integer
298
+ int left = NUM2INT(int_left);
299
+ int top = NUM2INT(int_top);
300
+ int right = NUM2INT(int_right);
301
+ int bottom = NUM2INT(int_bottom);
302
+ int buffer = NUM2INT(int_buffer);
303
+
304
+ // Declare variable dimension
305
+ char dimension[buffer];
306
+
307
+ // Native function getchars()
308
+ con_getchars(left, top, right, bottom, dimension);
309
+
310
+ // Return NULL value
311
+ return Qnil;
312
+ }
313
+
314
+ /*
315
+ * call-seq:
316
+ * getche() -> number
317
+ *
318
+ * Reads a single character from the keyboard and echoes it to the current text windows.
319
+ */
320
+ VALUE method_getche(VALUE self)
321
+ {
322
+ // Native function getche()
323
+ int character = getche();
324
+
325
+ // Return value character
326
+ return INT2NUM(character);
327
+ }
328
+
329
+ /*
330
+ * call-seq:
331
+ * getinfo() -> array
332
+ *
333
+ * Gets console information.
334
+ */
335
+ VALUE method_getinfo(VALUE self)
336
+ {
337
+ // Declare struct info
338
+ con_info info;
339
+
340
+ // Native function getinfo()
341
+ con_getinfo(& info);
342
+
343
+ // Set value info
344
+ int attr = info.attr;
345
+ int cx = info.cx;
346
+ int cy = info.cy;
347
+ int top = info.top;
348
+ int left = info.left;
349
+ int right = info.right;
350
+ int bottom = info.bottom;
351
+ int width = info.width;
352
+ int height = info.height;
353
+ int maxwidth = info.maxwidth;
354
+ int maxheight = info.maxheight;
355
+ int totalwidth = info.totalwidth;
356
+ int totalheight = info.totalheight;
357
+
358
+ // Create new Ruby hash
359
+ VALUE array = rb_ary_new();
360
+
361
+ // Populate Ruby hash
362
+ rb_ary_push(array, INT2NUM(attr));
363
+ rb_ary_push(array, INT2NUM(cx));
364
+ rb_ary_push(array, INT2NUM(cy));
365
+ rb_ary_push(array, INT2NUM(top));
366
+ rb_ary_push(array, INT2NUM(left));
367
+ rb_ary_push(array, INT2NUM(right));
368
+ rb_ary_push(array, INT2NUM(bottom));
369
+ rb_ary_push(array, INT2NUM(width));
370
+ rb_ary_push(array, INT2NUM(height));
371
+ rb_ary_push(array, INT2NUM(maxwidth));
372
+ rb_ary_push(array, INT2NUM(maxheight));
373
+ rb_ary_push(array, INT2NUM(totalwidth));
374
+ rb_ary_push(array, INT2NUM(totalheight));
375
+
376
+ // Return value hash
377
+ return array;
378
+ }
379
+
380
+ /*
381
+ * call-seq:
382
+ * gettext(left, top, right, bottom, buffer) -> nil
383
+ *
384
+ * Get the text of the memory area source out to the onscreen rectangle
385
+ * defined by left, top, right and bottom.
386
+ */
387
+ VALUE method_gettext(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
388
+ {
389
+ // Ruby conversion integer
390
+ int left = NUM2INT(int_left);
391
+ int top = NUM2INT(int_top);
392
+ int right = NUM2INT(int_right);
393
+ int bottom = NUM2INT(int_bottom);
394
+ int buffer = NUM2INT(int_buffer);
395
+
396
+ // Declare variable dimension
397
+ char dimension[buffer];
398
+
399
+ // Native function gettext()
400
+ gettext(left, top, right, bottom, dimension);
401
+
402
+ // Return NULL value
403
+ return Qnil;
404
+ }
405
+
406
+ /*
407
+ * call-seq:
408
+ * gettextinfo() -> array
409
+ *
410
+ * Gets text mode video information.
411
+ */
412
+ VALUE method_gettextinfo(VALUE self)
413
+ {
414
+ // Declare struct info
415
+ text_info info;
416
+
417
+ // Native function gettextinfo()
418
+ gettextinfo(& info);
419
+
420
+ // Set value info
421
+ int attribute = info.attribute;
422
+ int normattr = info.normattr;
423
+ int currmode = info.currmode;
424
+ int curx = info.curx;
425
+ int cury = info.cury;
426
+ int screenwidth = info.screenwidth;
427
+ int screenheight = info.screenheight;
428
+ int winleft = info.winleft;
429
+ int wintop = info.wintop;
430
+ int winright = info.winright;
431
+ int winbottom = info.winbottom;
432
+
433
+ // Create new Ruby hash
434
+ VALUE array = rb_ary_new();
435
+
436
+ // Populate Ruby hash
437
+ rb_ary_push(array, INT2NUM(attribute));
438
+ rb_ary_push(array, INT2NUM(normattr));
439
+ rb_ary_push(array, INT2NUM(currmode));
440
+ rb_ary_push(array, INT2NUM(curx));
441
+ rb_ary_push(array, INT2NUM(cury));
442
+ rb_ary_push(array, INT2NUM(screenwidth));
443
+ rb_ary_push(array, INT2NUM(screenheight));
444
+ rb_ary_push(array, INT2NUM(winleft));
445
+ rb_ary_push(array, INT2NUM(wintop));
446
+ rb_ary_push(array, INT2NUM(winright));
447
+ rb_ary_push(array, INT2NUM(winbottom));
448
+
449
+ // Return value hash
450
+ return array;
451
+ }
452
+
453
+ /*
454
+ * call-seq:
455
+ * gotoxy(x, y) -> nil
456
+ *
457
+ * Moves the cursor to the given position in the current text window.
458
+ */
459
+ VALUE method_gotoxy(VALUE self, VALUE int_x, VALUE int_y)
460
+ {
461
+ // Ruby conversion integer
462
+ int x = NUM2INT(int_x);
463
+ int y = NUM2INT(int_y);
464
+
465
+ // Native function gotoxy()
466
+ gotoxy(x + 1, y + 1);
467
+
468
+ // Return NULL value
469
+ return Qnil;
470
+ }
471
+
472
+ /*
473
+ * call-seq:
474
+ * insline() -> nil
475
+ *
476
+ * Inserts an empty line in the text window at the cursor
477
+ * position using the current text background color.
478
+ */
479
+ VALUE method_insline(VALUE self)
480
+ {
481
+ // Native function insline()
482
+ insline();
483
+
484
+ // Return NULL value
485
+ return Qnil;
486
+ }
487
+
488
+ /*
489
+ * call-seq:
490
+ * kbhit() -> number
491
+ *
492
+ * Checks to see if a keystroke is currently available.
493
+ */
494
+ VALUE method_kbhit(VALUE self)
495
+ {
496
+ // Native function kbhit()
497
+ int key = kbhit();
498
+
499
+ // Return value key
500
+ return INT2NUM(key);
501
+ }
502
+
503
+ /*
504
+ * call-seq:
505
+ * movetext(left, top, right, bottom, newleft, newtop) -> nil
506
+ *
507
+ * Copies the contents of the onscreen rectangle defined by left, top, right, and bottom
508
+ * to a new rectangle of the same dimensions.
509
+ */
510
+ VALUE method_movetext(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_newleft, VALUE int_newtop)
511
+ {
512
+ // Ruby conversion integer
513
+ int left = NUM2INT(int_left);
514
+ int top = NUM2INT(int_top);
515
+ int right = NUM2INT(int_right);
516
+ int bottom = NUM2INT(int_bottom);
517
+ int newleft = NUM2INT(int_newleft);
518
+ int newtop = NUM2INT(int_newtop);
519
+
520
+ // Native function movetext()
521
+ movetext(left, top, right, bottom, newleft, newtop);
522
+
523
+ // Return NULL value
524
+ return Qnil;
525
+ }
526
+
527
+ /*
528
+ * call-seq:
529
+ * put(left, top, right, bottom, buffer) -> nil
530
+ *
531
+ * Put the contents with attributes of the memory area source out to the onscreen
532
+ * rectangle defined by left, top, right and bottom.
533
+ */
534
+ VALUE method_put(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
535
+ {
536
+ // Ruby conversion integer
537
+ int left = NUM2INT(int_left);
538
+ int top = NUM2INT(int_top);
539
+ int right = NUM2INT(int_right);
540
+ int bottom = NUM2INT(int_bottom);
541
+ int buffer = NUM2INT(int_buffer);
542
+
543
+ // Declare variable dimension
544
+ int dimension[buffer];
545
+
546
+ // Native function put()
547
+ con_put(left, top, right, bottom, dimension);
548
+
549
+ // Return NULL value
550
+ return Qnil;
551
+ }
552
+
553
+ /*
554
+ * call-seq:
555
+ * putattrs(left, top, right, bottom, buffer) -> nil
556
+ *
557
+ * Put the attributes of the memory area source out to the onscreen
558
+ * rectangle defined by left, top, right and bottom.
559
+ */
560
+ VALUE method_putattrs(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
561
+ {
562
+ // Ruby conversion integer
563
+ int left = NUM2INT(int_left);
564
+ int top = NUM2INT(int_top);
565
+ int right = NUM2INT(int_right);
566
+ int bottom = NUM2INT(int_bottom);
567
+ int buffer = NUM2INT(int_buffer);
568
+
569
+ // Declare variable dimension
570
+ int dimension[buffer];
571
+
572
+ // Native function putattrs()
573
+ con_putattrs(left, top, right, bottom, dimension);
574
+
575
+ // Return NULL value
576
+ return Qnil;
577
+ }
578
+
579
+ /*
580
+ * call-seq:
581
+ * putch(character) -> number
582
+ *
583
+ * Outputs the character c to the current text window.
584
+ * It is a text-mode function that performs direct video output to the console.
585
+ */
586
+ VALUE method_putch(VALUE self, VALUE int_character)
587
+ {
588
+ // Ruby conversion integer
589
+ int character = NUM2INT(int_character);
590
+
591
+ // Native function putch()
592
+ int value = putchar(character);
593
+
594
+ // Return value character
595
+ return INT2NUM(value);
596
+ }
597
+
598
+ /*
599
+ * call-seq:
600
+ * putchars(left, top, right, bottom, buffer) -> nil
601
+ *
602
+ * Put the contents of the memory area source out to the onscreen
603
+ * rectangle defined by left, top, right and bottom.
604
+ */
605
+ VALUE method_putchars(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
606
+ {
607
+ // Ruby conversion integer
608
+ int left = NUM2INT(int_left);
609
+ int top = NUM2INT(int_top);
610
+ int right = NUM2INT(int_right);
611
+ int bottom = NUM2INT(int_bottom);
612
+ int buffer = NUM2INT(int_buffer);
613
+
614
+ // Declare variable dimension
615
+ char dimension[buffer];
616
+
617
+ // Native function getattrs()
618
+ con_putchars(left, top, right, bottom, dimension);
619
+
620
+ // Return NULL value
621
+ return Qnil;
622
+ }
623
+
624
+ /*
625
+ * call-seq:
626
+ * puttext(left, top, right, bottom, buffer) -> nil
627
+ *
628
+ * Put the text of the memory area source out to the onscreen
629
+ * rectangle defined by left, top, right and bottom.
630
+ */
631
+ VALUE method_puttext(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_buffer)
632
+ {
633
+ // Ruby conversion integer
634
+ int left = NUM2INT(int_left);
635
+ int top = NUM2INT(int_top);
636
+ int right = NUM2INT(int_right);
637
+ int bottom = NUM2INT(int_bottom);
638
+ int buffer = NUM2INT(int_buffer);
639
+
640
+ // Declare variable dimension
641
+ char dimension[buffer];
642
+
643
+ // Native function puttext()
644
+ puttext(left, top, right, bottom, dimension);
645
+
646
+ // Return NULL value
647
+ return Qnil;
648
+ }
649
+
650
+ /*
651
+ * call-seq:
652
+ * resize(width, height) -> nil
653
+ *
654
+ * Resize buffer and window size.
655
+ */
656
+ VALUE method_resize(VALUE self, VALUE int_width, VALUE int_height)
657
+ {
658
+ // Ruby conversion integer
659
+ int width = NUM2INT(int_width);
660
+ int height = NUM2INT(int_height);
661
+
662
+ // Native function resize()
663
+ con_resize(width, height);
664
+
665
+ // Return NULL value
666
+ return Qnil;
667
+ }
668
+
669
+ /*
670
+ * call-seq:
671
+ * scroll(left, top, right, bottom, newleft, newtop) -> nil
672
+ *
673
+ * The console window displays a portion of the active screen buffer.
674
+ */
675
+ VALUE method_scroll(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom, VALUE int_newleft, VALUE int_newtop)
676
+ {
677
+ // Ruby conversion integer
678
+ int left = NUM2INT(int_left);
679
+ int top = NUM2INT(int_top);
680
+ int right = NUM2INT(int_right);
681
+ int bottom = NUM2INT(int_bottom);
682
+ int newleft = NUM2INT(int_newleft);
683
+ int newtop = NUM2INT(int_newtop);
684
+
685
+ // Native function scroll()
686
+ con_scroll(left, top, right, bottom, newleft, newtop);
687
+
688
+ // Return NULL value
689
+ return Qnil;
690
+ }
691
+
692
+ /*
693
+ * call-seq:
694
+ * scrollup(left, top, right, bottom) -> nil
695
+ *
696
+ * Scroll up the text in current window text.
697
+ */
698
+ VALUE method_scrollup(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom)
699
+ {
700
+ // Ruby conversion integer
701
+ int left = NUM2INT(int_left);
702
+ int top = NUM2INT(int_top);
703
+ int right = NUM2INT(int_right);
704
+ int bottom = NUM2INT(int_bottom);
705
+
706
+ // Native function scrollup()
707
+ con_scrollup(left, top, right, bottom);
708
+
709
+ // Return NULL value
710
+ return Qnil;
711
+ }
712
+
713
+ /*
714
+ * call-seq:
715
+ * scrolldown(left, top, right, bottom) -> nil
716
+ *
717
+ * Scroll down the text in current window text.
718
+ */
719
+ VALUE method_scrolldown(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom)
720
+ {
721
+ // Ruby conversion integer
722
+ int left = NUM2INT(int_left);
723
+ int top = NUM2INT(int_top);
724
+ int right = NUM2INT(int_right);
725
+ int bottom = NUM2INT(int_bottom);
726
+
727
+ // Native function scrolldown()
728
+ con_scrolldown(left, top, right, bottom);
729
+
730
+ // Return NULL value
731
+ return Qnil;
732
+ }
733
+
734
+ /*
735
+ * call-seq:
736
+ * scrollleft(left, top, right, bottom) -> nil
737
+ *
738
+ * Scroll left the text in current window text.
739
+ */
740
+ VALUE method_scrollleft(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom)
741
+ {
742
+ // Ruby conversion integer
743
+ int left = NUM2INT(int_left);
744
+ int top = NUM2INT(int_top);
745
+ int right = NUM2INT(int_right);
746
+ int bottom = NUM2INT(int_bottom);
747
+
748
+ // Native function scrollleft()
749
+ con_scrollleft(left, top, right, bottom);
750
+
751
+ // Return NULL value
752
+ return Qnil;
753
+ }
754
+
755
+ /*
756
+ * call-seq:
757
+ * scrollright(left, top, right, bottom) -> nil
758
+ *
759
+ * Scroll right the text in current window text.
760
+ */
761
+ VALUE method_scrollright(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom)
762
+ {
763
+ // Ruby conversion integer
764
+ int left = NUM2INT(int_left);
765
+ int top = NUM2INT(int_top);
766
+ int right = NUM2INT(int_right);
767
+ int bottom = NUM2INT(int_bottom);
768
+
769
+ // Native function scrollright()
770
+ con_scrollright(left, top, right, bottom);
771
+
772
+ // Return NULL value
773
+ return Qnil;
774
+ }
775
+
776
+ /*
777
+ * call-seq:
778
+ * setbuffer(width, height) -> nil
779
+ *
780
+ * Define a window buffer size.
781
+ */
782
+ VALUE method_setbuffer(VALUE self, VALUE int_width, VALUE int_height)
783
+ {
784
+ // Ruby conversion integer
785
+ int width = NUM2INT(int_width);
786
+ int height = NUM2INT(int_height);
787
+
788
+ // Native function setbuffer()
789
+ con_setbuffer(width, height);
790
+
791
+ // Return NULL value
792
+ return Qnil;
793
+ }
794
+
795
+ /*
796
+ * call-seq:
797
+ * setcursortype(cursor) -> nil
798
+ *
799
+ * Sets the cursor type in range 0 (hide cursor) to 100 (solid block cursor).
800
+ */
801
+ VALUE method_setcursortype(VALUE self, VALUE int_cursor)
802
+ {
803
+ // Ruby conversion integer
804
+ int cursor = NUM2INT(int_cursor);
805
+
806
+ // Native function setcursortype()
807
+ _setcursortype(cursor);
808
+
809
+ // Return NULL value
810
+ return Qnil;
811
+ }
812
+
813
+ /*
814
+ * call-seq:
815
+ * settitle(title) -> nil
816
+ *
817
+ * Change the console window title.
818
+ */
819
+ VALUE method_settitle(VALUE self, VALUE string_title)
820
+ {
821
+ // Ruby conversion string
822
+ const char * title = StringValuePtr(string_title);
823
+
824
+ // Native function settitle()
825
+ con_settitle(title);
826
+
827
+ // Return NULL value
828
+ return Qnil;
829
+ }
830
+
831
+ /*
832
+ * call-seq:
833
+ * setwindow(left, top, right, bottom) -> nil
834
+ *
835
+ * Defines a text window onscreen. If the coordinates are in
836
+ * any way invalid, the call to window is ignored.
837
+ */
838
+ VALUE method_setwindow(VALUE self, VALUE int_left, VALUE int_top, VALUE int_right, VALUE int_bottom)
839
+ {
840
+ // Ruby conversion integer
841
+ int left = NUM2INT(int_left);
842
+ int top = NUM2INT(int_top);
843
+ int right = NUM2INT(int_right);
844
+ int bottom = NUM2INT(int_bottom);
845
+
846
+ // Native function setwindow()
847
+ con_setwindow(left, top, right, bottom);
848
+
849
+ // Return NULL value
850
+ return Qnil;
851
+ }
852
+
853
+ /*
854
+ * call-seq:
855
+ * sleep(seconds) -> nil
856
+ *
857
+ * The time interval for which execution is to be suspended, in seconds.
858
+ */
859
+ VALUE method_sleep(VALUE self, VALUE int_seconds)
860
+ {
861
+ // Ruby conversion integer
862
+ int seconds = NUM2INT(int_seconds);
863
+
864
+ // Native function sleep()
865
+ sleep(seconds);
866
+
867
+ // Return NULL value
868
+ return Qnil;
869
+ }
870
+
871
+ /*
872
+ * call-seq:
873
+ * textbackground(color) -> nil
874
+ *
875
+ * Selects the background character color.
876
+ */
877
+ VALUE method_textbackground(VALUE self, VALUE int_color)
878
+ {
879
+ // Ruby conversion integer
880
+ int color = NUM2INT(int_color);
881
+
882
+ // Native function textbackground()
883
+ textbackground(color);
884
+
885
+ // Return NULL value
886
+ return Qnil;
887
+ }
888
+
889
+ /*
890
+ * call-seq:
891
+ * textcolor(color) -> nil
892
+ *
893
+ * Selects the foreground character color.
894
+ */
895
+ VALUE method_textcolor(VALUE self, VALUE int_color)
896
+ {
897
+ // Ruby conversion integer
898
+ int color = NUM2INT(int_color);
899
+
900
+ // Native function textcolor()
901
+ textcolor(color);
902
+
903
+ // Return NULL value
904
+ return Qnil;
905
+ }
906
+
907
+ /*
908
+ * call-seq:
909
+ * ungetch(character) -> number
910
+ *
911
+ * Pushes the character ch back to the console, causing ch to be the next character read.
912
+ */
913
+ VALUE method_ungetch(VALUE self, VALUE int_character)
914
+ {
915
+ // Ruby conversion integer
916
+ int character = NUM2INT(int_character);
917
+
918
+ // Native function ungetch()
919
+ int value = ungetch(character);
920
+
921
+ // Return value character
922
+ return INT2NUM(value);
923
+ }
924
+
925
+ /*
926
+ * call-seq:
927
+ * wherex() -> number
928
+ *
929
+ * Gets the X coordinate of the current cursor position (within the current text window).
930
+ */
931
+ VALUE method_wherex(VALUE self)
932
+ {
933
+
934
+ // Native function wherex()
935
+ int position = wherex() - 1;
936
+
937
+ // Return NULL value
938
+ return INT2NUM(position);
939
+ }
940
+
941
+ /*
942
+ * call-seq:
943
+ * wherey() -> number
944
+ *
945
+ * Gets the Y coordinate of the current cursor position (within the current text window).
946
+ */
947
+ VALUE method_wherey(VALUE self)
948
+ {
949
+
950
+ // Native function wherex()
951
+ int position = wherey() - 1;
952
+
953
+ // Return NULL value
954
+ return INT2NUM(position);
955
+ }
956
+
957
+ // *************************
958
+ // * Conio Library Methods *
959
+ // *************************
960
+
961
+ void Init_libconio()
962
+ {
963
+ // Libconio Library
964
+ Libconio = rb_define_module("Libconio");
965
+
966
+ // Libconio Methods
967
+ rb_define_method(Libconio, "clreol", method_clreol, 0);
968
+ rb_define_method(Libconio, "clrscr", method_clrscr, 0);
969
+ rb_define_method(Libconio, "cputs", method_cputs, 1);
970
+ rb_define_method(Libconio, "crop", method_crop, 0);
971
+ rb_define_method(Libconio, "delay", method_delay, 1);
972
+ rb_define_method(Libconio, "delline", method_delline, 0);
973
+ rb_define_method(Libconio, "fill", method_fill, 6);
974
+ rb_define_method(Libconio, "fillattr", method_fillattr, 5);
975
+ rb_define_method(Libconio, "fillchar", method_fillchar, 4);
976
+ rb_define_method(Libconio, "fillcr", method_fillcr, 4);
977
+ rb_define_method(Libconio, "get", method_get, 5);
978
+ rb_define_method(Libconio, "getattrs", method_getattrs, 5);
979
+ rb_define_method(Libconio, "getch", method_getch, 0);
980
+ rb_define_method(Libconio, "getchars", method_getchars, 5);
981
+ rb_define_method(Libconio, "getche", method_getche, 0);
982
+ rb_define_method(Libconio, "getinfo", method_getinfo, 0);
983
+ rb_define_method(Libconio, "gettext", method_gettext, 5);
984
+ rb_define_method(Libconio, "gettextinfo", method_gettextinfo, 0);
985
+ rb_define_method(Libconio, "gotoxy", method_gotoxy, 2);
986
+ rb_define_method(Libconio, "insline", method_insline, 0);
987
+ rb_define_method(Libconio, "movetext", method_movetext, 6);
988
+ rb_define_method(Libconio, "put", method_put, 5);
989
+ rb_define_method(Libconio, "putattrs", method_putattrs, 5);
990
+ rb_define_method(Libconio, "putch", method_putch, 1);
991
+ rb_define_method(Libconio, "putchars", method_putchars, 5);
992
+ rb_define_method(Libconio, "puttext", method_puttext, 5);
993
+ rb_define_method(Libconio, "resize", method_resize, 2);
994
+ rb_define_method(Libconio, "scroll", method_scroll, 6);
995
+ rb_define_method(Libconio, "scrollup", method_scrollup, 4);
996
+ rb_define_method(Libconio, "scrolldown", method_scrolldown, 4);
997
+ rb_define_method(Libconio, "scrollleft", method_scrollleft, 4);
998
+ rb_define_method(Libconio, "scrollright", method_scrollright, 4);
999
+ rb_define_method(Libconio, "setbuffer", method_setbuffer, 2);
1000
+ rb_define_method(Libconio, "setcursortype", method_setcursortype, 1);
1001
+ rb_define_method(Libconio, "settitle", method_settitle, 1);
1002
+ rb_define_method(Libconio, "setwindow", method_setwindow, 4);
1003
+ rb_define_method(Libconio, "sleep", method_sleep, 1);
1004
+ rb_define_method(Libconio, "textbackground", method_textbackground, 1);
1005
+ rb_define_method(Libconio, "textcolor", method_textcolor, 1);
1006
+ rb_define_method(Libconio, "ungetch", method_ungetch, 1);
1007
+ rb_define_method(Libconio, "wherex", method_wherex, 0);
1008
+ rb_define_method(Libconio, "wherey", method_wherey, 0);
1009
+ }