io-console 0.7.1 → 0.7.2
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.
- checksums.yaml +4 -4
- data/.document +1 -0
- data/ext/io/console/console.c +152 -8
- data/ext/io/console/extconf.rb +0 -6
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea376ca7a23381cc7ad476248aa32fc95ff2fe19be07170f6eb4031b42e897ab
|
4
|
+
data.tar.gz: 321d946b43b46f279bb28d08c173c48b05e9c9a087d51cbcf1715153c772cda1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f4b33458250ec0e9039c9187d144fb9c851753c39b7e5191db26e2b8a898ce5ac6d6897330c93ae8eab1c6a4cd800a7af9f36ce83fd20b6caedfc52a12ed50
|
7
|
+
data.tar.gz: 4235ecf65e5e0b81c196d62a0a95649f708a29e2c300d645e99301dd3b6a470dc30b3cad6e2151b8ebf69c15c797962f62f55d6cdb935179f0656d2e450939af
|
data/.document
CHANGED
data/ext/io/console/console.c
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
/*
|
3
3
|
* console IO module
|
4
4
|
*/
|
5
|
+
|
6
|
+
static const char *const
|
7
|
+
IO_CONSOLE_VERSION = "0.7.2";
|
8
|
+
|
5
9
|
#include "ruby.h"
|
6
10
|
#include "ruby/io.h"
|
7
11
|
#include "ruby/thread.h"
|
@@ -75,6 +79,8 @@ getattr(int fd, conmode *t)
|
|
75
79
|
#define SET_LAST_ERROR (0)
|
76
80
|
#endif
|
77
81
|
|
82
|
+
#define CSI "\x1b\x5b"
|
83
|
+
|
78
84
|
static ID id_getc, id_console, id_close;
|
79
85
|
static ID id_gets, id_flush, id_chomp_bang;
|
80
86
|
|
@@ -896,6 +902,16 @@ console_set_winsize(VALUE io, VALUE size)
|
|
896
902
|
#endif
|
897
903
|
|
898
904
|
#ifdef _WIN32
|
905
|
+
/*
|
906
|
+
* call-seq:
|
907
|
+
* io.check_winsize_changed { ... } -> io
|
908
|
+
*
|
909
|
+
* Yields while console input events are queued.
|
910
|
+
*
|
911
|
+
* This method is Windows only.
|
912
|
+
*
|
913
|
+
* You must require 'io/console' to use this method.
|
914
|
+
*/
|
899
915
|
static VALUE
|
900
916
|
console_check_winsize_changed(VALUE io)
|
901
917
|
{
|
@@ -982,6 +998,14 @@ console_ioflush(VALUE io)
|
|
982
998
|
return io;
|
983
999
|
}
|
984
1000
|
|
1001
|
+
/*
|
1002
|
+
* call-seq:
|
1003
|
+
* io.beep
|
1004
|
+
*
|
1005
|
+
* Beeps on the output console.
|
1006
|
+
*
|
1007
|
+
* You must require 'io/console' to use this method.
|
1008
|
+
*/
|
985
1009
|
static VALUE
|
986
1010
|
console_beep(VALUE io)
|
987
1011
|
{
|
@@ -1049,6 +1073,17 @@ console_scroll(VALUE io, int line)
|
|
1049
1073
|
|
1050
1074
|
#include "win32_vk.inc"
|
1051
1075
|
|
1076
|
+
/*
|
1077
|
+
* call-seq:
|
1078
|
+
* io.pressed?(key) -> bool
|
1079
|
+
*
|
1080
|
+
* Returns +true+ if +key+ is pressed. +key+ may be a virtual key
|
1081
|
+
* code or its name (String or Symbol) with out "VK_" prefix.
|
1082
|
+
*
|
1083
|
+
* This method is Windows only.
|
1084
|
+
*
|
1085
|
+
* You must require 'io/console' to use this method.
|
1086
|
+
*/
|
1052
1087
|
static VALUE
|
1053
1088
|
console_key_pressed_p(VALUE io, VALUE k)
|
1054
1089
|
{
|
@@ -1142,7 +1177,7 @@ static VALUE
|
|
1142
1177
|
console_scroll(VALUE io, int line)
|
1143
1178
|
{
|
1144
1179
|
if (line) {
|
1145
|
-
VALUE s = rb_sprintf("
|
1180
|
+
VALUE s = rb_sprintf(CSI "%d%c", line < 0 ? -line : line,
|
1146
1181
|
line < 0 ? 'T' : 'S');
|
1147
1182
|
rb_io_write(io, s);
|
1148
1183
|
}
|
@@ -1192,6 +1227,14 @@ console_cursor_pos(VALUE io)
|
|
1192
1227
|
#endif
|
1193
1228
|
}
|
1194
1229
|
|
1230
|
+
/*
|
1231
|
+
* call-seq:
|
1232
|
+
* io.goto(line, column) -> io
|
1233
|
+
*
|
1234
|
+
* Set the cursor position at +line+ and +column+.
|
1235
|
+
*
|
1236
|
+
* You must require 'io/console' to use this method.
|
1237
|
+
*/
|
1195
1238
|
static VALUE
|
1196
1239
|
console_goto(VALUE io, VALUE y, VALUE x)
|
1197
1240
|
{
|
@@ -1204,7 +1247,7 @@ console_goto(VALUE io, VALUE y, VALUE x)
|
|
1204
1247
|
rb_syserr_fail(LAST_ERROR, 0);
|
1205
1248
|
}
|
1206
1249
|
#else
|
1207
|
-
rb_io_write(io, rb_sprintf("
|
1250
|
+
rb_io_write(io, rb_sprintf(CSI "%d;%dH", NUM2UINT(y)+1, NUM2UINT(x)+1));
|
1208
1251
|
#endif
|
1209
1252
|
return io;
|
1210
1253
|
}
|
@@ -1229,8 +1272,8 @@ console_move(VALUE io, int y, int x)
|
|
1229
1272
|
#else
|
1230
1273
|
if (x || y) {
|
1231
1274
|
VALUE s = rb_str_new_cstr("");
|
1232
|
-
if (y) rb_str_catf(s, "
|
1233
|
-
if (x) rb_str_catf(s, "
|
1275
|
+
if (y) rb_str_catf(s, CSI "%d%c", y < 0 ? -y : y, y < 0 ? 'A' : 'B');
|
1276
|
+
if (x) rb_str_catf(s, CSI "%d%c", x < 0 ? -x : x, x < 0 ? 'D' : 'C');
|
1234
1277
|
rb_io_write(io, s);
|
1235
1278
|
rb_io_flush(io);
|
1236
1279
|
}
|
@@ -1238,6 +1281,15 @@ console_move(VALUE io, int y, int x)
|
|
1238
1281
|
return io;
|
1239
1282
|
}
|
1240
1283
|
|
1284
|
+
/*
|
1285
|
+
* call-seq:
|
1286
|
+
* io.goto_column(column) -> io
|
1287
|
+
*
|
1288
|
+
* Set the cursor position at +column+ in the same line of the current
|
1289
|
+
* position.
|
1290
|
+
*
|
1291
|
+
* You must require 'io/console' to use this method.
|
1292
|
+
*/
|
1241
1293
|
static VALUE
|
1242
1294
|
console_goto_column(VALUE io, VALUE val)
|
1243
1295
|
{
|
@@ -1255,11 +1307,23 @@ console_goto_column(VALUE io, VALUE val)
|
|
1255
1307
|
rb_syserr_fail(LAST_ERROR, 0);
|
1256
1308
|
}
|
1257
1309
|
#else
|
1258
|
-
rb_io_write(io, rb_sprintf("
|
1310
|
+
rb_io_write(io, rb_sprintf(CSI "%dG", NUM2UINT(val)+1));
|
1259
1311
|
#endif
|
1260
1312
|
return io;
|
1261
1313
|
}
|
1262
1314
|
|
1315
|
+
/*
|
1316
|
+
* call-seq:
|
1317
|
+
* io.erase_line(mode) -> io
|
1318
|
+
*
|
1319
|
+
* Erases the line at the cursor corresponding to +mode+.
|
1320
|
+
* +mode+ may be either:
|
1321
|
+
* 0: after cursor
|
1322
|
+
* 1: before and cursor
|
1323
|
+
* 2: entire line
|
1324
|
+
*
|
1325
|
+
* You must require 'io/console' to use this method.
|
1326
|
+
*/
|
1263
1327
|
static VALUE
|
1264
1328
|
console_erase_line(VALUE io, VALUE val)
|
1265
1329
|
{
|
@@ -1290,11 +1354,23 @@ console_erase_line(VALUE io, VALUE val)
|
|
1290
1354
|
constat_clear(h, ws.wAttributes, w, *pos);
|
1291
1355
|
return io;
|
1292
1356
|
#else
|
1293
|
-
rb_io_write(io, rb_sprintf("
|
1357
|
+
rb_io_write(io, rb_sprintf(CSI "%dK", mode));
|
1294
1358
|
#endif
|
1295
1359
|
return io;
|
1296
1360
|
}
|
1297
1361
|
|
1362
|
+
/*
|
1363
|
+
* call-seq:
|
1364
|
+
* io.erase_screen(mode) -> io
|
1365
|
+
*
|
1366
|
+
* Erases the screen at the cursor corresponding to +mode+.
|
1367
|
+
* +mode+ may be either:
|
1368
|
+
* 0: after cursor
|
1369
|
+
* 1: before and cursor
|
1370
|
+
* 2: entire screen
|
1371
|
+
*
|
1372
|
+
* You must require 'io/console' to use this method.
|
1373
|
+
*/
|
1298
1374
|
static VALUE
|
1299
1375
|
console_erase_screen(VALUE io, VALUE val)
|
1300
1376
|
{
|
@@ -1332,11 +1408,21 @@ console_erase_screen(VALUE io, VALUE val)
|
|
1332
1408
|
}
|
1333
1409
|
constat_clear(h, ws.wAttributes, w, *pos);
|
1334
1410
|
#else
|
1335
|
-
rb_io_write(io, rb_sprintf("
|
1411
|
+
rb_io_write(io, rb_sprintf(CSI "%dJ", mode));
|
1336
1412
|
#endif
|
1337
1413
|
return io;
|
1338
1414
|
}
|
1339
1415
|
|
1416
|
+
/*
|
1417
|
+
* call-seq:
|
1418
|
+
* io.cursor = [line, column] -> io
|
1419
|
+
*
|
1420
|
+
* Same as <tt>io.goto(line, column)</tt>
|
1421
|
+
*
|
1422
|
+
* See IO#goto.
|
1423
|
+
*
|
1424
|
+
* You must require 'io/console' to use this method.
|
1425
|
+
*/
|
1340
1426
|
static VALUE
|
1341
1427
|
console_cursor_set(VALUE io, VALUE cpos)
|
1342
1428
|
{
|
@@ -1345,42 +1431,98 @@ console_cursor_set(VALUE io, VALUE cpos)
|
|
1345
1431
|
return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
|
1346
1432
|
}
|
1347
1433
|
|
1434
|
+
/*
|
1435
|
+
* call-seq:
|
1436
|
+
* io.cursor_up(n) -> io
|
1437
|
+
*
|
1438
|
+
* Moves the cursor up +n+ lines.
|
1439
|
+
*
|
1440
|
+
* You must require 'io/console' to use this method.
|
1441
|
+
*/
|
1348
1442
|
static VALUE
|
1349
1443
|
console_cursor_up(VALUE io, VALUE val)
|
1350
1444
|
{
|
1351
1445
|
return console_move(io, -NUM2INT(val), 0);
|
1352
1446
|
}
|
1353
1447
|
|
1448
|
+
/*
|
1449
|
+
* call-seq:
|
1450
|
+
* io.cursor_down(n) -> io
|
1451
|
+
*
|
1452
|
+
* Moves the cursor down +n+ lines.
|
1453
|
+
*
|
1454
|
+
* You must require 'io/console' to use this method.
|
1455
|
+
*/
|
1354
1456
|
static VALUE
|
1355
1457
|
console_cursor_down(VALUE io, VALUE val)
|
1356
1458
|
{
|
1357
1459
|
return console_move(io, +NUM2INT(val), 0);
|
1358
1460
|
}
|
1359
1461
|
|
1462
|
+
/*
|
1463
|
+
* call-seq:
|
1464
|
+
* io.cursor_left(n) -> io
|
1465
|
+
*
|
1466
|
+
* Moves the cursor left +n+ columns.
|
1467
|
+
*
|
1468
|
+
* You must require 'io/console' to use this method.
|
1469
|
+
*/
|
1360
1470
|
static VALUE
|
1361
1471
|
console_cursor_left(VALUE io, VALUE val)
|
1362
1472
|
{
|
1363
1473
|
return console_move(io, 0, -NUM2INT(val));
|
1364
1474
|
}
|
1365
1475
|
|
1476
|
+
/*
|
1477
|
+
* call-seq:
|
1478
|
+
* io.cursor_right(n) -> io
|
1479
|
+
*
|
1480
|
+
* Moves the cursor right +n+ columns.
|
1481
|
+
*
|
1482
|
+
* You must require 'io/console' to use this method.
|
1483
|
+
*/
|
1366
1484
|
static VALUE
|
1367
1485
|
console_cursor_right(VALUE io, VALUE val)
|
1368
1486
|
{
|
1369
1487
|
return console_move(io, 0, +NUM2INT(val));
|
1370
1488
|
}
|
1371
1489
|
|
1490
|
+
/*
|
1491
|
+
* call-seq:
|
1492
|
+
* io.scroll_forward(n) -> io
|
1493
|
+
*
|
1494
|
+
* Scrolls the entire scrolls forward +n+ lines.
|
1495
|
+
*
|
1496
|
+
* You must require 'io/console' to use this method.
|
1497
|
+
*/
|
1372
1498
|
static VALUE
|
1373
1499
|
console_scroll_forward(VALUE io, VALUE val)
|
1374
1500
|
{
|
1375
1501
|
return console_scroll(io, +NUM2INT(val));
|
1376
1502
|
}
|
1377
1503
|
|
1504
|
+
/*
|
1505
|
+
* call-seq:
|
1506
|
+
* io.scroll_backward(n) -> io
|
1507
|
+
*
|
1508
|
+
* Scrolls the entire scrolls backward +n+ lines.
|
1509
|
+
*
|
1510
|
+
* You must require 'io/console' to use this method.
|
1511
|
+
*/
|
1378
1512
|
static VALUE
|
1379
1513
|
console_scroll_backward(VALUE io, VALUE val)
|
1380
1514
|
{
|
1381
1515
|
return console_scroll(io, -NUM2INT(val));
|
1382
1516
|
}
|
1383
1517
|
|
1518
|
+
/*
|
1519
|
+
* call-seq:
|
1520
|
+
* io.clear_screen -> io
|
1521
|
+
*
|
1522
|
+
* Clears the entire screen and moves the cursor top-left corner.
|
1523
|
+
*
|
1524
|
+
* You must require 'io/console' to use this method.
|
1525
|
+
*/
|
1384
1526
|
static VALUE
|
1385
1527
|
console_clear_screen(VALUE io)
|
1386
1528
|
{
|
@@ -1675,14 +1817,16 @@ InitVM_console(void)
|
|
1675
1817
|
rb_define_method(rb_cIO, "getpass", console_getpass, -1);
|
1676
1818
|
rb_define_singleton_method(rb_cIO, "console", console_dev, -1);
|
1677
1819
|
{
|
1820
|
+
/* :stopdoc: */
|
1678
1821
|
VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable");
|
1822
|
+
/* :startdoc: */
|
1679
1823
|
rb_define_method(mReadable, "getch", io_getch, -1);
|
1680
1824
|
rb_define_method(mReadable, "getpass", io_getpass, -1);
|
1681
1825
|
}
|
1682
1826
|
{
|
1683
1827
|
/* :stopdoc: */
|
1684
1828
|
cConmode = rb_define_class_under(rb_cIO, "ConsoleMode", rb_cObject);
|
1685
|
-
rb_define_const(cConmode, "VERSION", rb_str_new_cstr(
|
1829
|
+
rb_define_const(cConmode, "VERSION", rb_str_new_cstr(IO_CONSOLE_VERSION));
|
1686
1830
|
rb_define_alloc_func(cConmode, conmode_alloc);
|
1687
1831
|
rb_undef_method(cConmode, "initialize");
|
1688
1832
|
rb_define_method(cConmode, "initialize_copy", conmode_init_copy, 1);
|
data/ext/io/console/extconf.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
|
-
version = ["../../..", "."].find do |dir|
|
5
|
-
break File.read(File.join(__dir__, dir, "io-console.gemspec"))[/^_VERSION\s*=\s*"(.*?)"/, 1]
|
6
|
-
rescue
|
7
|
-
end
|
8
|
-
|
9
4
|
have_func("rb_io_path")
|
10
5
|
have_func("rb_io_descriptor")
|
11
6
|
have_func("rb_io_get_write_io")
|
@@ -40,7 +35,6 @@ when true
|
|
40
35
|
elsif have_func("rb_scheduler_timeout") # 3.0
|
41
36
|
have_func("rb_io_wait")
|
42
37
|
end
|
43
|
-
$defs << "-D""IO_CONSOLE_VERSION=#{version}"
|
44
38
|
create_makefile("io/console") {|conf|
|
45
39
|
conf << "\n""VK_HEADER = #{vk_header}\n"
|
46
40
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: add console capabilities to IO instances.
|
14
14
|
email: nobu@ruby-lang.org
|
@@ -30,6 +30,7 @@ licenses:
|
|
30
30
|
- BSD-2-Clause
|
31
31
|
metadata:
|
32
32
|
source_code_url: https://github.com/ruby/io-console
|
33
|
+
changelog_uri: https://github.com/ruby/io-console/releases
|
33
34
|
post_install_message:
|
34
35
|
rdoc_options: []
|
35
36
|
require_paths:
|
@@ -45,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
48
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
49
|
+
rubygems_version: 3.6.0.dev
|
49
50
|
signing_key:
|
50
51
|
specification_version: 4
|
51
52
|
summary: Console interface
|