curses 1.4.0 → 1.4.4.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab24f57e39b3e38b5b9833d34f9bf5d6c2d55337f59693c628e30aa1f4f7324e
4
- data.tar.gz: a91a892d3c975670cccda3d99a5d7b7a9b0ff8e708aedaf87a2d57cc505d6338
3
+ metadata.gz: 68047bdb2e3dbf7718cfb3b610341764662471b0ed74ba0cedb749976cbfa01f
4
+ data.tar.gz: 58f8fcd098df7f5895446944acaa21b8f70cbe100ec4ba7aed434b4d9d91f0f7
5
5
  SHA512:
6
- metadata.gz: eff7ca406eeb081d6dcac3fe394e44577fdfdfa41428ecfb2068fd7de5288204df78081ff1e5bc41f5594c43194e8b20797ae6361cf7ffa028faf7301b085dd9
7
- data.tar.gz: d06b2e6d23e5eaac2b5c42cc9b433ef6e5ea25961e28dbe760d51b3fee5aadb2d5f68e76e1a7b1b066ecbcdc129b079c00e7e8427d7e31f4fe65950239eae9b5
6
+ metadata.gz: a510a9e12e08c77fbb855f519d48c923f95024fb12dbccfbae1138106ee3b9e47f1dcf08ef5fc3b66becaf2c00b79c4f7199691067177043ca2544b7c146e633
7
+ data.tar.gz: 7cefd71ef4136bc52fdfe4b1bb198310a6220f3fe5ae2c793c8e0fa2d8ca6eb7180f61b6fc80aa23d32f60e37ee81ce82a882512567e9474985dae777c8da3cf
@@ -6,7 +6,7 @@ jobs:
6
6
  test:
7
7
  strategy:
8
8
  matrix:
9
- ruby: [ head, 2.7, 2.6, 2.5 ]
9
+ ruby: [ head, 3.1, 2.7, 2.6 ]
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v2
@@ -7,19 +7,16 @@ jobs:
7
7
  runs-on: windows-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ '2.7.x', '2.6.x', '2.5.x' ]
10
+ ruby: [ 'mingw', 'mswin', '2.7', '2.6' ]
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
13
  with:
14
14
  submodules: true
15
15
  - name: Set up Ruby
16
- uses: actions/setup-ruby@v1
16
+ uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby }}
19
- - name: Install dependencies
20
- run: |
21
- gem install bundler --no-document
22
- bundle install
19
+ bundler-cache: true
23
20
  - name: Build package
24
21
  run: bundle exec rake build
25
22
  - name: Install package
data/History.md CHANGED
@@ -1,3 +1,24 @@
1
+ ### 1.4.3 / 2022-01-06
2
+
3
+ New features:
4
+
5
+ * Added flushinp, menu mark, fore and back functions.
6
+ Pull request #66 by Isty001.
7
+
8
+ ### 1.4.2 / 2021-06-14
9
+
10
+ New features:
11
+
12
+ * Added samples for addch, attron, mouse tracking and colors.
13
+ Pull request #62 by coezbek.
14
+
15
+ ### 1.4.1 / 2021-05-22
16
+
17
+ Bug fixes:
18
+
19
+ * Use chtype instead of char to support attributes
20
+ * Fixes for Ruby 3.1.
21
+
1
22
  ### 1.4.0 / 2020-12-10
2
23
 
3
24
  New features:
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # curses
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/curses.svg)](https://badge.fury.io/rb/curses)
4
- [![Build Status](https://travis-ci.org/ruby/curses.svg?branch=master)](https://travis-ci.org/ruby/curses)
5
- [![Build status](https://ci.appveyor.com/api/projects/status/kdvksgjo4fyd3c4m/branch/master?svg=true)](https://ci.appveyor.com/project/ruby/curses/branch/master)
4
+ [![ubuntu](https://github.com/ruby/curses/workflows/ubuntu/badge.svg)](https://github.com/ruby/curses/actions?query=workflow%3Aubuntu)
5
+ [![windows](https://github.com/ruby/curses/workflows/windows/badge.svg)](https://github.com/ruby/curses/actions?query=workflow%3Awindows)
6
+ [![macos](https://github.com/ruby/curses/workflows/macos/badge.svg)](https://github.com/ruby/curses/actions?query=workflow%3Amacos)
6
7
 
7
8
  * https://github.com/ruby/curses
8
9
  * https://github.com/ruby/curses/issues
@@ -28,8 +29,13 @@ Or
28
29
 
29
30
  $ apt install libncursesw5-dev
30
31
 
31
- On mingw, `gem install curses` will install pre-built PDCurses, so you
32
+ On Windows, `gem install curses` will build bundled PDCurses, so you
32
33
  don't need to install extra libraries.
34
+ However, if you prefer ncurses to PDCurses, specify the following option:
35
+
36
+ > gem install curses -- --use-system-libraries
37
+
38
+ On mingw, you need DevKit to compile the extension library.
33
39
 
34
40
  ## Documentation
35
41
 
@@ -42,57 +48,16 @@ After checking out the repo, run `bundle install` to install dependencies.
42
48
  To compile the extension library, run `bundle exec rake compile`.
43
49
 
44
50
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `curses.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
-
46
- ### Cross compilation for Windows on Debian GNU/Linux based platforms
47
-
48
- 1. Install development environment fo 32- and 64-bit Windows.
49
-
50
- ```
51
- $ sudo apt-get install mingw-w64
52
- ```
53
-
54
- 2. Install rake-compiler.
55
-
56
- ```
57
- $ gem install rake-compiler
58
- ```
59
-
60
- 3. Compile multiple versions of Ruby.
61
-
62
- ```
63
- $ rake-compiler cross-ruby HOST=i686-w64-mingw32 VERSION=2.2.6
64
- $ rake-compiler cross-ruby HOST=i686-w64-mingw32 VERSION=2.3.3
65
- $ rake-compiler cross-ruby HOST=i686-w64-mingw32 VERSION=2.4.0
66
- $ rake-compiler cross-ruby HOST=x86_64-w64-mingw32 VERSION=2.2.6
67
- $ rake-compiler cross-ruby HOST=x86_64-w64-mingw32 VERSION=2.3.3
68
- $ rake-compiler cross-ruby HOST=x86_64-w64-mingw32 VERSION=2.4.0
69
- ```
70
-
71
- 3. Compile PDCurses.
72
-
73
- ```
74
- $ rake build:pdcurses
75
- ```
76
-
77
- 5. Compile curses.gem.
78
-
79
- ```
80
- $ rake RUBY_CC_VERSION=2.3.3:2.4.0 cross clean compile native gem
81
- ```
82
-
83
- Binary gems are generated in pkg/.
84
-
85
51
  ## License
86
52
 
87
53
  curses is released under the Ruby and 2-clause BSD licenses. See COPYING for
88
54
  details.
89
55
 
90
- Binary gems for mingw32 include a forked version of PDCurses, which is in
91
- the public domain:
56
+ It includes a forked version of PDCurses, which is in the public domain:
92
57
 
93
58
  https://github.com/Bill-Gray/PDCurses
94
59
 
95
- The version for Win32 console mode in the win32 subdirectory is used.
60
+ The version for Win32 console mode in the wincon subdirectory is used.
96
61
 
97
62
  [1]: https://bugs.ruby-lang.org/issues/8584
98
63
  [2]: https://github.com/ruby/ruby/commit/9c5b2fd8aa0fd343ad094d47a638cfd3f6ae0a81
data/curses.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new { |s|
2
2
  s.name = "curses"
3
- s.version = "1.4.0"
3
+ s.version = "1.4.4.beta.1"
4
4
  s.author = ["Shugo Maeda", 'Eric Hodel']
5
5
  s.email = ["shugo@ruby-lang.org", 'drbrain@segment7.net']
6
6
  s.homepage = "https://github.com/ruby/curses"
@@ -9,7 +9,7 @@ Gem::Specification.new { |s|
9
9
  s.files = `git ls-files --recurse-submodules -z`.split("\x0")
10
10
  s.extensions = ["ext/curses/extconf.rb"]
11
11
  s.require_path = "lib"
12
- s.required_ruby_version = Gem::Requirement.new('>= 2.1.0')
12
+ s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
13
13
  s.licenses = ['Ruby', 'BSD-2-Clause']
14
14
  s.add_development_dependency 'bundler'
15
15
  s.add_development_dependency 'rake'
data/ext/curses/curses.c CHANGED
@@ -82,8 +82,19 @@
82
82
  # define USE_MOUSE 1
83
83
  #endif
84
84
 
85
- #define NUM2CH NUM2CHR
86
- #define CH2FIX CHR2FIX
85
+ #define OBJ2CHTYPE rb_obj2chtype_inline
86
+
87
+ static inline chtype
88
+ rb_obj2chtype_inline(VALUE x)
89
+ {
90
+ if (RB_TYPE_P(x, RUBY_T_STRING)) {
91
+ ID id_ord;
92
+
93
+ CONST_ID(id_ord, "ord");
94
+ x = rb_funcall(x, id_ord, 0);
95
+ }
96
+ return NUM2CHTYPE(x);
97
+ }
87
98
 
88
99
  static VALUE mCurses;
89
100
  static VALUE mKey;
@@ -291,7 +302,7 @@ static void curses_finalize(VALUE);
291
302
  * see also Curses.stdscr
292
303
  */
293
304
  static VALUE
294
- curses_init_screen(void)
305
+ curses_init_screen(VALUE self)
295
306
  {
296
307
  if (rb_stdscr) return rb_stdscr;
297
308
  initscr();
@@ -314,7 +325,7 @@ curses_init_screen(void)
314
325
  *
315
326
  * Many curses functions use this window.
316
327
  */
317
- #define curses_stdscr curses_init_screen
328
+ #define curses_stdscr() curses_init_screen(Qnil)
318
329
 
319
330
  /*
320
331
  * Document-method: Curses.close_screen
@@ -330,7 +341,7 @@ curses_init_screen(void)
330
341
  *
331
342
  */
332
343
  static VALUE
333
- curses_close_screen(void)
344
+ curses_close_screen(VALUE self)
334
345
  {
335
346
  curses_stdscr();
336
347
  #ifdef HAVE_ISENDWIN
@@ -370,7 +381,7 @@ curses_finalize(VALUE dummy)
370
381
  * returns +false+ otherwise.
371
382
  */
372
383
  static VALUE
373
- curses_closed(void)
384
+ curses_closed(VALUE self)
374
385
  {
375
386
  curses_stdscr();
376
387
  if (isendwin()) {
@@ -420,7 +431,7 @@ curses_erase(VALUE obj)
420
431
  * Clears to the end of line, that the cursor is currently on.
421
432
  */
422
433
  static VALUE
423
- curses_clrtoeol(void)
434
+ curses_clrtoeol(VALUE self)
424
435
  {
425
436
  curses_stdscr();
426
437
  clrtoeol();
@@ -609,6 +620,20 @@ curses_nonl(VALUE obj)
609
620
  return Qnil;
610
621
  }
611
622
 
623
+ /*
624
+ * Document-method: Curses.flushinp
625
+ *
626
+ * The flushinp routine throws away any typeahead that has been
627
+ * typed by the user and has not yet been read by the program.
628
+ */
629
+ static VALUE
630
+ curses_flushinp(VALUE obj)
631
+ {
632
+ curses_stdscr();
633
+ flushinp();
634
+ return Qnil;
635
+ }
636
+
612
637
  /*
613
638
  * Document-method: Curses.beep
614
639
  *
@@ -747,7 +772,7 @@ static VALUE
747
772
  curses_inch(VALUE obj)
748
773
  {
749
774
  curses_stdscr();
750
- return CH2FIX(inch());
775
+ return CHTYPE2NUM(inch());
751
776
  }
752
777
 
753
778
  /*
@@ -762,7 +787,7 @@ static VALUE
762
787
  curses_addch(VALUE obj, VALUE ch)
763
788
  {
764
789
  curses_stdscr();
765
- addch(NUM2CH(ch));
790
+ addch(OBJ2CHTYPE(ch));
766
791
  return Qnil;
767
792
  }
768
793
 
@@ -777,7 +802,7 @@ static VALUE
777
802
  curses_insch(VALUE obj, VALUE ch)
778
803
  {
779
804
  curses_stdscr();
780
- insch(NUM2CH(ch));
805
+ insch(OBJ2CHTYPE(ch));
781
806
  return Qnil;
782
807
  }
783
808
 
@@ -949,7 +974,7 @@ curses_keyname(VALUE obj, VALUE c)
949
974
  * Returns the number of lines on the screen
950
975
  */
951
976
  static VALUE
952
- curses_lines(void)
977
+ curses_lines(VALUE self)
953
978
  {
954
979
  return INT2FIX(LINES);
955
980
  }
@@ -960,7 +985,7 @@ curses_lines(void)
960
985
  * Returns the number of columns on the screen
961
986
  */
962
987
  static VALUE
963
- curses_cols(void)
988
+ curses_cols(VALUE self)
964
989
  {
965
990
  return INT2FIX(COLS);
966
991
  }
@@ -1106,7 +1131,7 @@ curses_bkgdset(VALUE obj, VALUE ch)
1106
1131
  {
1107
1132
  #ifdef HAVE_BKGDSET
1108
1133
  curses_stdscr();
1109
- bkgdset(NUM2CHTYPE(ch));
1134
+ bkgdset(OBJ2CHTYPE(ch));
1110
1135
  #endif
1111
1136
  return Qnil;
1112
1137
  }
@@ -1127,7 +1152,7 @@ curses_bkgd(VALUE obj, VALUE ch)
1127
1152
  {
1128
1153
  #ifdef HAVE_BKGD
1129
1154
  curses_stdscr();
1130
- return (bkgd(NUM2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
1155
+ return (bkgd(OBJ2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
1131
1156
  #else
1132
1157
  return Qfalse;
1133
1158
  #endif
@@ -1341,7 +1366,7 @@ curses_can_change_color(VALUE obj)
1341
1366
  return can_change_color() ? Qtrue : Qfalse;
1342
1367
  }
1343
1368
 
1344
- #if defined(HAVE_COLORS)
1369
+ #if defined(HAVE_COLORS) || defined(COLORS)
1345
1370
  /*
1346
1371
  * Document-method: Curses.color
1347
1372
  *
@@ -1548,7 +1573,7 @@ static VALUE
1548
1573
  curses_mousemask(VALUE obj, VALUE mask)
1549
1574
  {
1550
1575
  curses_stdscr();
1551
- return INT2NUM(mousemask(NUM2UINT(mask),NULL));
1576
+ return ULONG2NUM(mousemask(NUM2UINT(mask),NULL));
1552
1577
  }
1553
1578
 
1554
1579
  #define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \
@@ -1589,7 +1614,12 @@ DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z)
1589
1614
  * Returns the current mouse's button state. Use this with the button state
1590
1615
  * constants to determine which buttons were pressed.
1591
1616
  */
1592
- DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate)
1617
+ static VALUE curs_mouse_bstate(VALUE mouse)
1618
+ {
1619
+ struct mousedata *mdata;
1620
+ GetMOUSE(mouse, mdata);
1621
+ return ULONG2NUM(mdata->mevent->bstate);
1622
+ }
1593
1623
  #undef define_curs_mouse_member
1594
1624
  #endif /* USE_MOUSE */
1595
1625
 
@@ -1681,7 +1711,7 @@ window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
1681
1711
  struct windata *winp;
1682
1712
  WINDOW *window;
1683
1713
 
1684
- curses_init_screen();
1714
+ curses_init_screen(Qnil);
1685
1715
  TypedData_Get_Struct(obj, struct windata, &windata_type, winp);
1686
1716
  if (winp->window) delwin(winp->window);
1687
1717
  window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left));
@@ -2178,7 +2208,7 @@ window_begx(VALUE obj)
2178
2208
 
2179
2209
  /*
2180
2210
  * Document-method: Curses::Window.box
2181
- * call-seq: box(vert, hor)
2211
+ * call-seq: box(vert = nil, hor = nil, corn = nil)
2182
2212
  *
2183
2213
  * set the characters to frame the window in.
2184
2214
  * The vertical +vert+ and horizontal +hor+ character.
@@ -2193,16 +2223,18 @@ window_box(int argc, VALUE *argv, VALUE self)
2193
2223
  struct windata *winp;
2194
2224
  VALUE vert, hor, corn;
2195
2225
 
2196
- rb_scan_args(argc, argv, "21", &vert, &hor, &corn);
2226
+ rb_scan_args(argc, argv, "03", &vert, &hor, &corn);
2197
2227
 
2198
2228
  GetWINDOW(self, winp);
2199
- box(winp->window, NUM2CH(vert), NUM2CH(hor));
2229
+ box(winp->window,
2230
+ NIL_P(vert) ? 0 : OBJ2CHTYPE(vert),
2231
+ NIL_P(hor) ? 0 : OBJ2CHTYPE(hor));
2200
2232
 
2201
2233
  if (!NIL_P(corn)) {
2202
2234
  int cur_x, cur_y, x, y;
2203
2235
  chtype c;
2204
2236
 
2205
- c = NUM2CH(corn);
2237
+ c = OBJ2CHTYPE(corn);
2206
2238
  getyx(winp->window, cur_y, cur_x);
2207
2239
  x = NUM2INT(window_maxx(self)) - 1;
2208
2240
  y = NUM2INT(window_maxy(self)) - 1;
@@ -2269,7 +2301,7 @@ window_inch(VALUE obj)
2269
2301
  struct windata *winp;
2270
2302
 
2271
2303
  GetWINDOW(obj, winp);
2272
- return CH2FIX(winch(winp->window));
2304
+ return CHTYPE2NUM(winch(winp->window));
2273
2305
  }
2274
2306
 
2275
2307
  /*
@@ -2286,7 +2318,7 @@ window_addch(VALUE obj, VALUE ch)
2286
2318
  struct windata *winp;
2287
2319
 
2288
2320
  GetWINDOW(obj, winp);
2289
- waddch(winp->window, NUM2CH(ch));
2321
+ waddch(winp->window, OBJ2CHTYPE(ch));
2290
2322
 
2291
2323
  return Qnil;
2292
2324
  }
@@ -2304,7 +2336,7 @@ window_insch(VALUE obj, VALUE ch)
2304
2336
  struct windata *winp;
2305
2337
 
2306
2338
  GetWINDOW(obj, winp);
2307
- winsch(winp->window, NUM2CH(ch));
2339
+ winsch(winp->window, OBJ2CHTYPE(ch));
2308
2340
 
2309
2341
  return Qnil;
2310
2342
  }
@@ -2732,7 +2764,7 @@ window_bkgdset(VALUE obj, VALUE ch)
2732
2764
  struct windata *winp;
2733
2765
 
2734
2766
  GetWINDOW(obj,winp);
2735
- wbkgdset(winp->window, NUM2CHTYPE(ch));
2767
+ wbkgdset(winp->window, OBJ2CHTYPE(ch));
2736
2768
  #endif
2737
2769
  return Qnil;
2738
2770
  }
@@ -2753,7 +2785,7 @@ window_bkgd(VALUE obj, VALUE ch)
2753
2785
  struct windata *winp;
2754
2786
 
2755
2787
  GetWINDOW(obj,winp);
2756
- return (wbkgd(winp->window, NUM2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
2788
+ return (wbkgd(winp->window, OBJ2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
2757
2789
  #else
2758
2790
  return Qfalse;
2759
2791
  #endif
@@ -2921,7 +2953,7 @@ pad_initialize(VALUE obj, VALUE h, VALUE w)
2921
2953
  struct windata *padp;
2922
2954
  WINDOW *window;
2923
2955
 
2924
- curses_init_screen();
2956
+ curses_init_screen(Qnil);
2925
2957
  TypedData_Get_Struct(obj, struct windata, &windata_type, padp);
2926
2958
  if (padp->window) delwin(padp->window);
2927
2959
  window = newpad(NUM2INT(h), NUM2INT(w));
@@ -3092,7 +3124,7 @@ item_initialize(VALUE obj, VALUE name, VALUE description)
3092
3124
  {
3093
3125
  struct itemdata *itemp;
3094
3126
 
3095
- curses_init_screen();
3127
+ curses_init_screen(Qnil);
3096
3128
  TypedData_Get_Struct(obj, struct itemdata, &itemdata_type, itemp);
3097
3129
  if (itemp->item) {
3098
3130
  rb_raise(rb_eRuntimeError, "already initialized item");
@@ -3305,7 +3337,7 @@ menu_initialize(VALUE obj, VALUE items)
3305
3337
  ID id_new;
3306
3338
 
3307
3339
  Check_Type(items, T_ARRAY);
3308
- curses_init_screen();
3340
+ curses_init_screen(Qnil);
3309
3341
  TypedData_Get_Struct(obj, struct menudata, &menudata_type, menup);
3310
3342
  if (menup->menu) {
3311
3343
  rb_raise(rb_eRuntimeError, "already initialized menu");
@@ -3600,6 +3632,121 @@ menu_set_format(VALUE obj, VALUE rows, VALUE cols)
3600
3632
  return obj;
3601
3633
  }
3602
3634
 
3635
+ /*
3636
+ * Document-method: Curses::Menu#mark=
3637
+ *
3638
+ * call-seq:
3639
+ * mark=(str)
3640
+ *
3641
+ * Set the mark string to distinguish the selected items
3642
+ */
3643
+ static VALUE
3644
+ menu_set_mark(VALUE obj, VALUE mark)
3645
+ {
3646
+ struct menudata *menup;
3647
+
3648
+ GetMENU(obj, menup);
3649
+ set_menu_mark(menup->menu, StringValueCStr(mark));
3650
+
3651
+ return obj;
3652
+ }
3653
+
3654
+ /*
3655
+ * Document-method: Curses::Menu#mark
3656
+ *
3657
+ * call-seq:
3658
+ * mark
3659
+ *
3660
+ * Get the Menu's mark string
3661
+ */
3662
+ static VALUE
3663
+ menu_get_mark(VALUE obj)
3664
+ {
3665
+ struct menudata *menup;
3666
+ const char *mark;
3667
+
3668
+ GetMENU(obj, menup);
3669
+ mark = menu_mark(menup->menu);
3670
+
3671
+ return rb_external_str_new_with_enc(mark, strlen(mark), terminal_encoding);
3672
+ }
3673
+
3674
+ /*
3675
+ * Document-method: Curses::Menu#fore=
3676
+ *
3677
+ * call-seq:
3678
+ * fore=(attr)
3679
+ *
3680
+ * Sets the foreground attribute of menu.
3681
+ * This is the highlight used for selected menu items.
3682
+ */
3683
+ static VALUE
3684
+ menu_set_fore(VALUE obj, VALUE attr)
3685
+ {
3686
+ struct menudata *menup;
3687
+
3688
+ GetMENU(obj, menup);
3689
+ set_menu_fore(menup->menu, NUM2CHTYPE(attr));
3690
+
3691
+ return attr;
3692
+ }
3693
+
3694
+ /*
3695
+ * Document-method: Curses::Menu#fore
3696
+ *
3697
+ * call-seq:
3698
+ * fore
3699
+ *
3700
+ * Sets the foreground attribute of menu.
3701
+ * This is the highlight used for selected menu items.
3702
+ */
3703
+ static VALUE
3704
+ menu_get_fore(VALUE obj, VALUE attr)
3705
+ {
3706
+ struct menudata *menup;
3707
+
3708
+ GetMENU(obj, menup);
3709
+
3710
+ return CHTYPE2NUM(menu_fore(menup->menu));
3711
+ }
3712
+
3713
+ /*
3714
+ * Document-method: Curses::Menu#set_back
3715
+ *
3716
+ * call-seq:
3717
+ * set_back(attr)
3718
+ *
3719
+ * Get the background attribute of menu.
3720
+ */
3721
+ static VALUE
3722
+ menu_set_back(VALUE obj, VALUE attr)
3723
+ {
3724
+ struct menudata *menup;
3725
+
3726
+ GetMENU(obj, menup);
3727
+ CHTYPE2NUM(set_menu_back(menup->menu, NUM2CHTYPE(attr)));
3728
+
3729
+ return attr;
3730
+ }
3731
+
3732
+ /*
3733
+ * Document-method: Curses::Menu#back
3734
+ *
3735
+ * call-seq:
3736
+ * back
3737
+ *
3738
+ * Get the background attribute of menu.
3739
+ */
3740
+ static VALUE
3741
+ menu_get_back(VALUE obj, VALUE attr)
3742
+ {
3743
+ struct menudata *menup;
3744
+
3745
+ GetMENU(obj, menup);
3746
+
3747
+ return CHTYPE2NUM(menu_back(menup->menu));
3748
+ }
3749
+
3603
3750
  /*
3604
3751
  * Document-method: Curses::Menu#format
3605
3752
  *
@@ -3761,7 +3908,7 @@ field_initialize(VALUE obj, VALUE height, VALUE width,
3761
3908
  {
3762
3909
  struct fielddata *fieldp;
3763
3910
 
3764
- curses_init_screen();
3911
+ curses_init_screen(Qnil);
3765
3912
  TypedData_Get_Struct(obj, struct fielddata, &fielddata_type, fieldp);
3766
3913
  if (fieldp->field) {
3767
3914
  rb_raise(rb_eRuntimeError, "already initialized field");
@@ -4219,7 +4366,7 @@ form_initialize(VALUE obj, VALUE fields)
4219
4366
  int i;
4220
4367
 
4221
4368
  Check_Type(fields, T_ARRAY);
4222
- curses_init_screen();
4369
+ curses_init_screen(Qnil);
4223
4370
  TypedData_Get_Struct(obj, struct formdata, &formdata_type, formp);
4224
4371
  if (formp->form) {
4225
4372
  rb_raise(rb_eRuntimeError, "already initialized form");
@@ -4719,7 +4866,7 @@ Init_curses(void)
4719
4866
  rb_define_module_function(mCurses, "init_screen", curses_init_screen, 0);
4720
4867
  rb_define_module_function(mCurses, "close_screen", curses_close_screen, 0);
4721
4868
  rb_define_module_function(mCurses, "closed?", curses_closed, 0);
4722
- rb_define_module_function(mCurses, "stdscr", curses_stdscr, 0);
4869
+ rb_define_module_function(mCurses, "stdscr", curses_init_screen, 0);
4723
4870
  rb_define_module_function(mCurses, "refresh", curses_refresh, 0);
4724
4871
  rb_define_module_function(mCurses, "doupdate", curses_doupdate, 0);
4725
4872
  rb_define_module_function(mCurses, "clear", curses_clear, 0);
@@ -4735,6 +4882,7 @@ Init_curses(void)
4735
4882
  rb_define_module_function(mCurses, "nocrmode", curses_nocbreak, 0);
4736
4883
  rb_define_module_function(mCurses, "nl", curses_nl, 0);
4737
4884
  rb_define_module_function(mCurses, "nonl", curses_nonl, 0);
4885
+ rb_define_module_function(mCurses, "flushinp", curses_flushinp, 0);
4738
4886
  rb_define_module_function(mCurses, "beep", curses_beep, 0);
4739
4887
  rb_define_module_function(mCurses, "flash", curses_flash, 0);
4740
4888
  rb_define_module_function(mCurses, "ungetch", curses_ungetch, 1);
@@ -4859,7 +5007,7 @@ Init_curses(void)
4859
5007
  * win.close
4860
5008
  *
4861
5009
  */
4862
- cWindow = rb_define_class_under(mCurses, "Window", rb_cData);
5010
+ cWindow = rb_define_class_under(mCurses, "Window", rb_cObject);
4863
5011
  rb_define_alloc_func(cWindow, window_s_allocate);
4864
5012
  rb_define_method(cWindow, "initialize", window_initialize, 4);
4865
5013
  rb_define_method(cWindow, "subwin", window_subwin, 4);
@@ -4943,7 +5091,7 @@ Init_curses(void)
4943
5091
  #endif
4944
5092
 
4945
5093
  #ifdef HAVE_MENU
4946
- cItem = rb_define_class_under(mCurses, "Item", rb_cData);
5094
+ cItem = rb_define_class_under(mCurses, "Item", rb_cObject);
4947
5095
  rb_define_alloc_func(cItem, item_s_allocate);
4948
5096
  rb_define_method(cItem, "initialize", item_initialize, 2);
4949
5097
  rb_define_method(cItem, "==", item_eq, 1);
@@ -4954,7 +5102,7 @@ Init_curses(void)
4954
5102
  rb_define_method(cItem, "opts_off", item_opts_off_m, 1);
4955
5103
  rb_define_method(cItem, "opts", item_opts_m, 0);
4956
5104
 
4957
- cMenu = rb_define_class_under(mCurses, "Menu", rb_cData);
5105
+ cMenu = rb_define_class_under(mCurses, "Menu", rb_cObject);
4958
5106
  rb_define_alloc_func(cMenu, menu_s_allocate);
4959
5107
  rb_define_method(cMenu, "initialize", menu_initialize, 1);
4960
5108
  rb_define_method(cMenu, "post", menu_post, 0);
@@ -4970,6 +5118,12 @@ Init_curses(void)
4970
5118
  rb_define_method(cMenu, "scale", menu_scale, 0);
4971
5119
  rb_define_method(cMenu, "set_format", menu_set_format, 2);
4972
5120
  rb_define_method(cMenu, "format", menu_format_m, 0);
5121
+ rb_define_method(cMenu, "mark=", menu_set_mark, 1);
5122
+ rb_define_method(cMenu, "mark", menu_get_mark, 0);
5123
+ rb_define_method(cMenu, "fore=", menu_set_fore, 1);
5124
+ rb_define_method(cMenu, "fore", menu_get_fore, 0);
5125
+ rb_define_method(cMenu, "back=", menu_set_back, 1);
5126
+ rb_define_method(cMenu, "back", menu_get_back, 0);
4973
5127
  rb_define_method(cMenu, "set_opts", menu_set_opts, 1);
4974
5128
  rb_define_method(cMenu, "opts_on", menu_opts_on_m, 1);
4975
5129
  rb_define_method(cMenu, "opts_off", menu_opts_off_m, 1);
@@ -4977,7 +5131,7 @@ Init_curses(void)
4977
5131
  #endif
4978
5132
 
4979
5133
  #ifdef HAVE_FORM
4980
- cField = rb_define_class_under(mCurses, "Field", rb_cData);
5134
+ cField = rb_define_class_under(mCurses, "Field", rb_cObject);
4981
5135
  rb_define_alloc_func(cField, field_s_allocate);
4982
5136
  rb_define_method(cField, "initialize", field_initialize, 6);
4983
5137
  rb_define_method(cField, "set_buffer", field_set_buffer, 2);
@@ -5004,7 +5158,7 @@ Init_curses(void)
5004
5158
  rb_define_method(cField, "max=", field_set_max, 1);
5005
5159
  rb_define_method(cField, "set_type", field_set_type, -1);
5006
5160
 
5007
- cForm = rb_define_class_under(mCurses, "Form", rb_cData);
5161
+ cForm = rb_define_class_under(mCurses, "Form", rb_cObject);
5008
5162
  rb_define_alloc_func(cForm, form_s_allocate);
5009
5163
  rb_define_method(cForm, "initialize", form_initialize, 1);
5010
5164
  rb_define_method(cForm, "post", form_post, 0);
data/sample/addch.rb ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # require_relative "../lib/curses"
3
+ require 'curses'
4
+
5
+ include Curses
6
+
7
+ init_screen
8
+ begin
9
+ addstr("The following letter A should be BOLD and UNDERLINED by using addch:\n")
10
+ addch('A'.ord | A_BOLD | A_UNDERLINE)
11
+
12
+ addstr("\nIt should look the same as when using attron and addstr:\n")
13
+ attron(A_BOLD | A_UNDERLINE)
14
+ addstr("A")
15
+ getch
16
+
17
+ ensure
18
+ close_screen
19
+ end
@@ -0,0 +1,32 @@
1
+ require "curses"
2
+ include Curses
3
+
4
+ init_screen
5
+ begin
6
+ attrs = {
7
+ A_NORMAL => 'Normal display (no highlight)',
8
+ A_STANDOUT => 'Best highlighting mode of the terminal',
9
+ A_UNDERLINE => 'Underlining',
10
+ A_REVERSE => 'Reverse video',
11
+ A_BLINK => 'Blinking',
12
+ A_DIM => 'Half bright',
13
+ A_BOLD => 'Extra bright or bold',
14
+ A_PROTECT => 'Protected mode',
15
+ A_INVIS => 'Invisible or blank mode',
16
+ A_ALTCHARSET => 'Alternate character set',
17
+ }
18
+
19
+ longest_description = attrs.values.map(&:size).max
20
+ attrs.each { |attribute, description|
21
+
22
+ attrset(A_NORMAL)
23
+ addstr("#{description.ljust(longest_description)}: ")
24
+
25
+ attrset(attribute)
26
+ addstr([*('a'..'z'), *('0'..'9')].join + "\n")
27
+ }
28
+ getch
29
+
30
+ ensure
31
+ close_screen
32
+ end
data/sample/colors.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "curses"
2
+ include Curses
3
+
4
+ begin
5
+ init_screen
6
+
7
+ if !Curses.has_colors?
8
+ addstr "This Terminal does not support colors!"
9
+ else
10
+ start_color
11
+
12
+ addstr "This Terminal supports #{colors} colors.\n"
13
+
14
+ Curses.colors.times { |i|
15
+ Curses.init_pair(i, i, 0)
16
+ attrset(color_pair(i))
17
+ addstr("#{i.to_s.rjust(3)} ")
18
+ addstr("\n") if i == 15 || (i > 16 && (i - 15) % 36 == 0)
19
+ }
20
+ end
21
+
22
+ getch
23
+
24
+ ensure
25
+ close_screen
26
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Mouse movement tracking using CSI 1003 and 1006 (SGR). Will print a cursor that moves with the mouse.
4
+ #
5
+
6
+ require "curses"
7
+ include Curses
8
+
9
+ @positions = []
10
+
11
+ def draw_cursor(y, x, button, state)
12
+
13
+ # Keep a trail of 10 previous positions visible on the screen
14
+ if @positions.size >= 10
15
+ y_old, x_old = @positions.shift
16
+ setpos(y_old, x_old)
17
+ addstr(" ")
18
+ end
19
+
20
+ setpos(2, 1)
21
+ addstr("Mouse is at y=#{y.to_s.ljust(3)} x=#{x.to_s.ljust(3)} button=#{button.to_s.ljust(3)} #{'%08b' % button}")
22
+
23
+ setpos(y, x)
24
+ addstr("+")
25
+ @positions << [y, x]
26
+ end
27
+
28
+ init_screen
29
+ crmode
30
+ noecho
31
+ stdscr.box('|', "-")
32
+ setpos(1,1)
33
+ addstr("Please move your mouse. Press 'q' to close.")
34
+
35
+ begin
36
+ # Switch on mouse continous position reporting
37
+ print("\x1b[?1003h")
38
+
39
+ # Also enable SGR extended reporting, because otherwise we can only
40
+ # receive values up to 160x94. Everything else confuses Ruby Curses.
41
+ print("\x1b[?1006h")
42
+
43
+ loop do
44
+ c = get_char
45
+ case c
46
+ when "q"
47
+ return
48
+ when "\e" # ESC
49
+ case get_char
50
+ when '['
51
+ csi = ""
52
+ loop do
53
+ d = get_char
54
+ csi += d
55
+ if d.ord >= 0x40 && d.ord <= 0x7E
56
+ break
57
+ end
58
+ end
59
+ if /<(\d+);(\d+);(\d+)(m|M)/ =~ csi
60
+ button = $1.to_i
61
+ x = $2.to_i
62
+ y = $3.to_i
63
+ state = $4
64
+ draw_cursor(y, x, button, state)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ ensure
71
+ print("\x1b[?1003l")
72
+ print("\x1b[?1006l")
73
+ close_screen
74
+ end
75
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.4.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-10 00:00:00.000000000 Z
12
+ date: 2022-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,23 +53,25 @@ files:
53
53
  - ".github/workflows/windows.yml"
54
54
  - ".gitignore"
55
55
  - ".gitmodules"
56
- - ".travis.yml"
57
56
  - BSDL
58
57
  - COPYING
59
58
  - Gemfile
60
59
  - History.md
61
60
  - README.md
62
61
  - Rakefile
63
- - appveyor.yml
64
62
  - curses.gemspec
65
63
  - ext/curses/curses.c
66
64
  - ext/curses/depend
67
65
  - ext/curses/extconf.rb
68
66
  - lib/curses.rb
67
+ - sample/addch.rb
68
+ - sample/attr_demo.rb
69
+ - sample/colors.rb
69
70
  - sample/form.rb
70
71
  - sample/hello.rb
71
72
  - sample/menu.rb
72
73
  - sample/mouse.rb
74
+ - sample/mouse_move.rb
73
75
  - sample/rain.rb
74
76
  - sample/view.rb
75
77
  - sample/view2.rb
@@ -330,14 +332,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
330
332
  requirements:
331
333
  - - ">="
332
334
  - !ruby/object:Gem::Version
333
- version: 2.1.0
335
+ version: 2.6.0
334
336
  required_rubygems_version: !ruby/object:Gem::Requirement
335
337
  requirements:
336
- - - ">="
338
+ - - ">"
337
339
  - !ruby/object:Gem::Version
338
- version: '0'
340
+ version: 1.3.1
339
341
  requirements: []
340
- rubygems_version: 3.2.0.rc.1
342
+ rubygems_version: 3.4.0.dev
341
343
  signing_key:
342
344
  specification_version: 4
343
345
  summary: A Ruby binding for curses, ncurses, and PDCurses. curses is an extension
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- language: ruby
3
- notifications:
4
- email:
5
- recipients:
6
- - drbrain@segment7.net
7
- - shugo@ruby-lang.org
8
- rvm:
9
- - 2.2.10
10
- - 2.3.8
11
- - 2.4.5
12
- - 2.5.3
13
- - 2.6.1
14
- - ruby-head
15
- before_install: gem install bundler -v '<2'
16
- script: rake compile
data/appveyor.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- clone_depth: 10
3
- install:
4
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
5
- - appveyor DownloadFile http://dl.bintray.com/oneclick/OpenKnapsack/x64/pdcurses-3.4-x64-windows.tar.lzma
6
- - 7z e pdcurses-3.4-x64-windows.tar.lzma
7
- - 7z x -y -oC:\Ruby%ruby_version% pdcurses-3.4-x64-windows.tar
8
- - bundle install
9
- build_script:
10
- - rake -rdevkit compile -- --with-curses-dir=C:\Ruby%ruby_version%
11
- test: off
12
- deploy: off
13
- environment:
14
- matrix:
15
- - ruby_version: "22-x64"
16
- - ruby_version: "23-x64"