curses 1.5.4 → 1.6.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.
- checksums.yaml +4 -4
- data/.github/workflows/push_gem.yml +1 -1
- data/README.md +1 -1
- data/curses.gemspec +1 -1
- data/ext/curses/curses.c +156 -15
- data/ext/curses/extconf.rb +3 -1
- data/sample/colors.rb +16 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6c663a808bf8a6c76299105512ed71e57db768054d26ffd51527b254b6fed9f
|
|
4
|
+
data.tar.gz: 6c088c90e25573f398d2051b84be37c394acace504948ed831d039e1e625efe2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4404453e5b9c2d2db0697131c1253f3363d553e51f7427822e4ec7d5c70b3959a457cb4791c694be979d54bf0dec13dbf2b7904bab6115a0b7722979982829c
|
|
7
|
+
data.tar.gz: 5a6e4d31948c5808601fec0e34633b185586657af4e6bb8d95e07b9144991e0ff3e5f15584985997e9847232510d55c99b9b9821a052ef7784607a1aa2f8214b
|
|
@@ -24,7 +24,7 @@ jobs:
|
|
|
24
24
|
steps:
|
|
25
25
|
# Set up
|
|
26
26
|
- name: Harden Runner
|
|
27
|
-
uses: step-security/harden-runner@
|
|
27
|
+
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
|
28
28
|
with:
|
|
29
29
|
egress-policy: audit
|
|
30
30
|
|
data/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Type the following command, and see `[rdoc]` of curses:
|
|
|
53
53
|
|
|
54
54
|
## Limitations
|
|
55
55
|
|
|
56
|
-
*
|
|
56
|
+
* On ncurses 6+ compiled with extended color support, more than 256 color pairs are supported transparently via the extended colors API (`init_extended_pair`, etc.). Use `Curses.support_extended_colors?` to check at runtime.
|
|
57
57
|
|
|
58
58
|
## Developers
|
|
59
59
|
|
data/curses.gemspec
CHANGED
data/ext/curses/curses.c
CHANGED
|
@@ -1321,7 +1321,11 @@ curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
|
|
|
1321
1321
|
{
|
|
1322
1322
|
/* may have to raise exception on ERR */
|
|
1323
1323
|
curses_stdscr();
|
|
1324
|
+
#ifdef HAVE_INIT_EXTENDED_PAIR
|
|
1325
|
+
return (init_extended_pair(NUM2INT(pair), NUM2INT(f), NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
|
1326
|
+
#else
|
|
1324
1327
|
return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
|
1328
|
+
#endif
|
|
1325
1329
|
}
|
|
1326
1330
|
|
|
1327
1331
|
/*
|
|
@@ -1345,8 +1349,13 @@ curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
|
|
|
1345
1349
|
{
|
|
1346
1350
|
/* may have to raise exception on ERR */
|
|
1347
1351
|
curses_stdscr();
|
|
1352
|
+
#ifdef HAVE_INIT_EXTENDED_COLOR
|
|
1353
|
+
return (init_extended_color(NUM2INT(color), NUM2INT(r),
|
|
1354
|
+
NUM2INT(g), NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
|
1355
|
+
#else
|
|
1348
1356
|
return (init_color(NUM2INT(color),NUM2INT(r),
|
|
1349
1357
|
NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
|
1358
|
+
#endif
|
|
1350
1359
|
}
|
|
1351
1360
|
|
|
1352
1361
|
/*
|
|
@@ -1397,11 +1406,22 @@ curses_colors(VALUE obj)
|
|
|
1397
1406
|
static VALUE
|
|
1398
1407
|
curses_color_content(VALUE obj, VALUE color)
|
|
1399
1408
|
{
|
|
1400
|
-
short r,g,b;
|
|
1401
|
-
|
|
1402
1409
|
curses_stdscr();
|
|
1403
|
-
|
|
1404
|
-
|
|
1410
|
+
#ifdef HAVE_EXTENDED_COLOR_CONTENT
|
|
1411
|
+
{
|
|
1412
|
+
int r, g, b;
|
|
1413
|
+
if (extended_color_content(NUM2INT(color), &r, &g, &b) == ERR)
|
|
1414
|
+
return Qnil;
|
|
1415
|
+
return rb_ary_new3(3, INT2FIX(r), INT2FIX(g), INT2FIX(b));
|
|
1416
|
+
}
|
|
1417
|
+
#else
|
|
1418
|
+
{
|
|
1419
|
+
short r, g, b;
|
|
1420
|
+
if (color_content(NUM2INT(color), &r, &g, &b) == ERR)
|
|
1421
|
+
return Qnil;
|
|
1422
|
+
return rb_ary_new3(3, INT2FIX(r), INT2FIX(g), INT2FIX(b));
|
|
1423
|
+
}
|
|
1424
|
+
#endif
|
|
1405
1425
|
}
|
|
1406
1426
|
|
|
1407
1427
|
|
|
@@ -1430,11 +1450,22 @@ curses_color_pairs(VALUE obj)
|
|
|
1430
1450
|
static VALUE
|
|
1431
1451
|
curses_pair_content(VALUE obj, VALUE pair)
|
|
1432
1452
|
{
|
|
1433
|
-
short f,b;
|
|
1434
|
-
|
|
1435
1453
|
curses_stdscr();
|
|
1436
|
-
|
|
1437
|
-
|
|
1454
|
+
#ifdef HAVE_EXTENDED_PAIR_CONTENT
|
|
1455
|
+
{
|
|
1456
|
+
int f, b;
|
|
1457
|
+
if (extended_pair_content(NUM2INT(pair), &f, &b) == ERR)
|
|
1458
|
+
return Qnil;
|
|
1459
|
+
return rb_ary_new3(2, INT2FIX(f), INT2FIX(b));
|
|
1460
|
+
}
|
|
1461
|
+
#else
|
|
1462
|
+
{
|
|
1463
|
+
short f, b;
|
|
1464
|
+
if (pair_content(NUM2INT(pair), &f, &b) == ERR)
|
|
1465
|
+
return Qnil;
|
|
1466
|
+
return rb_ary_new3(2, INT2FIX(f), INT2FIX(b));
|
|
1467
|
+
}
|
|
1468
|
+
#endif
|
|
1438
1469
|
}
|
|
1439
1470
|
|
|
1440
1471
|
/*
|
|
@@ -1465,6 +1496,41 @@ curses_pair_number(VALUE obj, VALUE attrs)
|
|
|
1465
1496
|
curses_stdscr();
|
|
1466
1497
|
return INT2FIX(PAIR_NUMBER(NUM2CHTYPE(attrs)));
|
|
1467
1498
|
}
|
|
1499
|
+
|
|
1500
|
+
/*
|
|
1501
|
+
* Document-method: Curses.support_extended_colors?
|
|
1502
|
+
*
|
|
1503
|
+
* Returns +true+ if the ncurses library was compiled with extended color
|
|
1504
|
+
* support (i.e., init_extended_pair, init_extended_color, etc. are available),
|
|
1505
|
+
* +false+ otherwise.
|
|
1506
|
+
*/
|
|
1507
|
+
static VALUE
|
|
1508
|
+
curses_support_extended_colors(VALUE obj)
|
|
1509
|
+
{
|
|
1510
|
+
#if defined(HAVE_INIT_EXTENDED_PAIR) && defined(HAVE_INIT_EXTENDED_COLOR) && \
|
|
1511
|
+
defined(HAVE_EXTENDED_COLOR_CONTENT) && defined(HAVE_EXTENDED_PAIR_CONTENT)
|
|
1512
|
+
return Qtrue;
|
|
1513
|
+
#else
|
|
1514
|
+
return Qfalse;
|
|
1515
|
+
#endif
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
/*
|
|
1519
|
+
* Document-method: Curses.reset_color_pairs
|
|
1520
|
+
*
|
|
1521
|
+
* Resets all color pairs to undefined. Requires ncurses 6.1+.
|
|
1522
|
+
*/
|
|
1523
|
+
#ifdef HAVE_RESET_COLOR_PAIRS
|
|
1524
|
+
static VALUE
|
|
1525
|
+
curses_reset_color_pairs(VALUE obj)
|
|
1526
|
+
{
|
|
1527
|
+
curses_stdscr();
|
|
1528
|
+
reset_color_pairs();
|
|
1529
|
+
return Qnil;
|
|
1530
|
+
}
|
|
1531
|
+
#else
|
|
1532
|
+
#define curses_reset_color_pairs rb_f_notimplement
|
|
1533
|
+
#endif
|
|
1468
1534
|
#endif /* USE_COLOR */
|
|
1469
1535
|
|
|
1470
1536
|
#ifdef USE_MOUSE
|
|
@@ -2717,7 +2783,7 @@ window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
|
|
|
2717
2783
|
#endif
|
|
2718
2784
|
}
|
|
2719
2785
|
|
|
2720
|
-
#if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
|
|
2786
|
+
#if defined(USE_COLOR) && ((defined(HAVE_WATTR_SET) && defined(HAVE_WATTR_GET)) || defined(HAVE_WCOLOR_SET))
|
|
2721
2787
|
/*
|
|
2722
2788
|
* Document-method: Curses::Window.color_set
|
|
2723
2789
|
* call-seq: color_set(col)
|
|
@@ -2729,13 +2795,26 @@ static VALUE
|
|
|
2729
2795
|
window_color_set(VALUE obj, VALUE col)
|
|
2730
2796
|
{
|
|
2731
2797
|
struct windata *winp;
|
|
2732
|
-
int res;
|
|
2733
2798
|
|
|
2734
2799
|
GetWINDOW(obj, winp);
|
|
2735
|
-
|
|
2736
|
-
|
|
2800
|
+
#if defined(HAVE_WATTR_SET) && defined(HAVE_WATTR_GET)
|
|
2801
|
+
/* Use wattr_set to support pair numbers > 255; preserve existing attrs. */
|
|
2802
|
+
{
|
|
2803
|
+
attr_t attrs;
|
|
2804
|
+
#ifdef NCURSES_PAIRS_T
|
|
2805
|
+
NCURSES_PAIRS_T current_pair;
|
|
2806
|
+
#else
|
|
2807
|
+
short current_pair;
|
|
2808
|
+
#endif
|
|
2809
|
+
if (wattr_get(winp->window, &attrs, ¤t_pair, NULL) == ERR)
|
|
2810
|
+
return Qfalse;
|
|
2811
|
+
return (wattr_set(winp->window, attrs, NUM2INT(col), NULL) == OK) ? Qtrue : Qfalse;
|
|
2812
|
+
}
|
|
2813
|
+
#else
|
|
2814
|
+
return (wcolor_set(winp->window, NUM2INT(col), NULL) == OK) ? Qtrue : Qfalse;
|
|
2815
|
+
#endif
|
|
2737
2816
|
}
|
|
2738
|
-
#endif /* defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) */
|
|
2817
|
+
#endif /* defined(USE_COLOR) && ((defined(HAVE_WATTR_SET) && defined(HAVE_WATTR_GET)) || defined(HAVE_WCOLOR_SET)) */
|
|
2739
2818
|
|
|
2740
2819
|
/*
|
|
2741
2820
|
* Document-method: Curses::Window.scroll
|
|
@@ -2870,6 +2949,60 @@ window_attrset(VALUE obj, VALUE attrs)
|
|
|
2870
2949
|
#endif
|
|
2871
2950
|
}
|
|
2872
2951
|
|
|
2952
|
+
/*
|
|
2953
|
+
* Document-method: Curses::Window.attr_set
|
|
2954
|
+
* call-seq: attr_set(attrs, pair)
|
|
2955
|
+
*
|
|
2956
|
+
* Sets the current attributes and color pair of the given window.
|
|
2957
|
+
* Unlike Curses::Window.attrset, this method accepts an extended color
|
|
2958
|
+
* pair number (> 255) when the ncurses extended colors API is available.
|
|
2959
|
+
*
|
|
2960
|
+
* Returns +true+ on success, +false+ on failure.
|
|
2961
|
+
*
|
|
2962
|
+
* see also system manual curs_attr(3)
|
|
2963
|
+
*/
|
|
2964
|
+
#ifdef HAVE_WATTR_SET
|
|
2965
|
+
static VALUE
|
|
2966
|
+
window_attr_set(VALUE obj, VALUE attrs, VALUE pair)
|
|
2967
|
+
{
|
|
2968
|
+
struct windata *winp;
|
|
2969
|
+
|
|
2970
|
+
GetWINDOW(obj, winp);
|
|
2971
|
+
return (wattr_set(winp->window, NUM2UINT(attrs), NUM2INT(pair), NULL) == OK) ? Qtrue : Qfalse;
|
|
2972
|
+
}
|
|
2973
|
+
#endif
|
|
2974
|
+
|
|
2975
|
+
/*
|
|
2976
|
+
* Document-method: Curses::Window.attr_get
|
|
2977
|
+
* call-seq: attr_get => [attrs, pair]
|
|
2978
|
+
*
|
|
2979
|
+
* Returns a 2-element Array of the current attributes and color pair
|
|
2980
|
+
* of the given window. The color pair number may exceed 255 when the
|
|
2981
|
+
* ncurses extended colors API is available.
|
|
2982
|
+
*
|
|
2983
|
+
* Returns +nil+ on failure.
|
|
2984
|
+
*
|
|
2985
|
+
* see also system manual curs_attr(3)
|
|
2986
|
+
*/
|
|
2987
|
+
#ifdef HAVE_WATTR_GET
|
|
2988
|
+
static VALUE
|
|
2989
|
+
window_attr_get(VALUE obj)
|
|
2990
|
+
{
|
|
2991
|
+
struct windata *winp;
|
|
2992
|
+
attr_t attrs;
|
|
2993
|
+
#ifdef NCURSES_PAIRS_T
|
|
2994
|
+
NCURSES_PAIRS_T pair;
|
|
2995
|
+
#else
|
|
2996
|
+
short pair;
|
|
2997
|
+
#endif
|
|
2998
|
+
|
|
2999
|
+
GetWINDOW(obj, winp);
|
|
3000
|
+
if (wattr_get(winp->window, &attrs, &pair, NULL) == ERR)
|
|
3001
|
+
return Qnil;
|
|
3002
|
+
return rb_ary_new3(2, UINT2NUM(attrs), INT2NUM(pair));
|
|
3003
|
+
}
|
|
3004
|
+
#endif
|
|
3005
|
+
|
|
2873
3006
|
/*
|
|
2874
3007
|
* Document-method: Curses::Window.bkgdset
|
|
2875
3008
|
* call-seq: bkgdset(ch)
|
|
@@ -5071,6 +5204,8 @@ Init_curses(void)
|
|
|
5071
5204
|
rb_define_module_function(mCurses, "pair_content", curses_pair_content, 1);
|
|
5072
5205
|
rb_define_module_function(mCurses, "color_pair", curses_color_pair, 1);
|
|
5073
5206
|
rb_define_module_function(mCurses, "pair_number", curses_pair_number, 1);
|
|
5207
|
+
rb_define_module_function(mCurses, "support_extended_colors?", curses_support_extended_colors, 0);
|
|
5208
|
+
rb_define_module_function(mCurses, "reset_color_pairs", curses_reset_color_pairs, 0);
|
|
5074
5209
|
#endif /* USE_COLOR */
|
|
5075
5210
|
#ifdef USE_MOUSE
|
|
5076
5211
|
rb_define_module_function(mCurses, "getmouse", curses_getmouse, 0);
|
|
@@ -5203,9 +5338,9 @@ Init_curses(void)
|
|
|
5203
5338
|
rb_define_method(cWindow, "move", window_move, 2);
|
|
5204
5339
|
rb_define_method(cWindow, "move_relative", window_move_relative, 2);
|
|
5205
5340
|
rb_define_method(cWindow, "setpos", window_setpos, 2);
|
|
5206
|
-
#if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
|
|
5341
|
+
#if defined(USE_COLOR) && ((defined(HAVE_WATTR_SET) && defined(HAVE_WATTR_GET)) || defined(HAVE_WCOLOR_SET))
|
|
5207
5342
|
rb_define_method(cWindow, "color_set", window_color_set, 1);
|
|
5208
|
-
#endif
|
|
5343
|
+
#endif
|
|
5209
5344
|
rb_define_method(cWindow, "cury", window_cury, 0);
|
|
5210
5345
|
rb_define_method(cWindow, "curx", window_curx, 0);
|
|
5211
5346
|
rb_define_method(cWindow, "maxy", window_maxy, 0);
|
|
@@ -5236,6 +5371,12 @@ Init_curses(void)
|
|
|
5236
5371
|
rb_define_method(cWindow, "attroff", window_attroff, 1);
|
|
5237
5372
|
rb_define_method(cWindow, "attron", window_attron, 1);
|
|
5238
5373
|
rb_define_method(cWindow, "attrset", window_attrset, 1);
|
|
5374
|
+
#ifdef HAVE_WATTR_SET
|
|
5375
|
+
rb_define_method(cWindow, "attr_set", window_attr_set, 2);
|
|
5376
|
+
#endif
|
|
5377
|
+
#ifdef HAVE_WATTR_GET
|
|
5378
|
+
rb_define_method(cWindow, "attr_get", window_attr_get, 0);
|
|
5379
|
+
#endif
|
|
5239
5380
|
rb_define_method(cWindow, "bkgdset", window_bkgdset, 1);
|
|
5240
5381
|
rb_define_method(cWindow, "bkgd", window_bkgd, 1);
|
|
5241
5382
|
rb_define_method(cWindow, "getbkgd", window_getbkgd, 0);
|
data/ext/curses/extconf.rb
CHANGED
|
@@ -119,7 +119,9 @@ if header_library
|
|
|
119
119
|
def_prog_mode reset_prog_mode timeout wtimeout nodelay
|
|
120
120
|
init_color wcolor_set use_default_colors assume_default_colors
|
|
121
121
|
newpad unget_wch get_wch wget_wch PDC_get_key_modifiers
|
|
122
|
-
chgat wchgat newterm
|
|
122
|
+
chgat wchgat newterm
|
|
123
|
+
init_extended_color init_extended_pair extended_color_content
|
|
124
|
+
extended_pair_content reset_color_pairs wattr_set wattr_get)
|
|
123
125
|
have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
|
|
124
126
|
end
|
|
125
127
|
convertible_int('chtype', [["#undef MOUSE_MOVED\n"]]+curses) or abort
|
data/sample/colors.rb
CHANGED
|
@@ -5,6 +5,7 @@ include Curses
|
|
|
5
5
|
|
|
6
6
|
# The TERM environment variable should be set to xterm-256color etc. to
|
|
7
7
|
# use 256 colors. Curses.colors returns the color numbers of the terminal.
|
|
8
|
+
# With ncurses 6+ extended color support, color_pairs may exceed 256.
|
|
8
9
|
|
|
9
10
|
begin
|
|
10
11
|
init_screen
|
|
@@ -14,14 +15,24 @@ begin
|
|
|
14
15
|
else
|
|
15
16
|
start_color
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
extended = Curses.support_extended_colors?
|
|
19
|
+
addstr "This Terminal supports #{colors} colors, #{color_pairs} pairs"
|
|
20
|
+
addstr extended ? " (extended).\n" : ".\n"
|
|
21
|
+
|
|
22
|
+
(extended ? [512, color_pairs].min : colors).times { |i|
|
|
23
|
+
next if i == 0
|
|
24
|
+
Curses.init_pair(i, i % colors, (i / colors) % colors)
|
|
25
|
+
if extended
|
|
26
|
+
# color_pair() encodes into chtype and can't handle pairs > 255;
|
|
27
|
+
# use color_set on stdscr instead, which calls wattr_set internally.
|
|
28
|
+
stdscr.color_set(i)
|
|
29
|
+
else
|
|
30
|
+
attrset(color_pair(i))
|
|
31
|
+
end
|
|
22
32
|
addstr("#{i.to_s.rjust(3)} ")
|
|
23
33
|
addstr("\n") if i == 15 || (i > 16 && (i - 15) % 36 == 0)
|
|
24
34
|
}
|
|
35
|
+
stdscr.color_set(0)
|
|
25
36
|
end
|
|
26
37
|
|
|
27
38
|
getch
|