rcurses 3.7.1 → 3.7.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44240d40ec0eed615d785bf0cbd288470b722a1162a6d2e30a1f1045dfed3a01
4
- data.tar.gz: 0316a667c756e3f99b6fe6d0ee1d0956f673058139cbbbb615d48882b0b799b7
3
+ metadata.gz: d300db2c5840595d0716539687b0c5d6de38d0d60543373f49edf3bd19b953dd
4
+ data.tar.gz: 5eed2e21c1912e456640cf54516ffcadece0d7bac70862fd63965299a97c60f1
5
5
  SHA512:
6
- metadata.gz: 2a54a18fb906abebebbf5a7066a4448ba25c47a80df7fced9289c86d17caf09d62b2bbb959863470fb2243ead27de62d9278a3843e9c075a16a6885120250f5f
7
- data.tar.gz: 0dd21b911092c501c146ad354ca5dfd58cb84bdff142237ed2b9be677b5f5a18ee8c40283194794affc493097fb9d8a9cc37120a08a787eaa14718920630722a
6
+ metadata.gz: 29eac670b3bd278d0b4f3a76ca892278510a94243318ca7f5aa29b05a95b336ec5b4911763c198b73b1028114525d438d7f9da9f323315ef337a8258ba206ebc
7
+ data.tar.gz: 32dd6bcad30a491872f7e6880e811a6326b5df317bff395e6e6d431d976ebeb252521eb093c5dc7959d6d5303e7c056f39e4f335198888a8cf2533a345a27e7f
data/lib/rcurses/input.rb CHANGED
@@ -1,114 +1,126 @@
1
1
  module Rcurses
2
2
  module Input
3
- def getchr(t = nil)
4
- # 1) Read a byte (with optional timeout)
3
+ def getchr(t = nil, flush: true)
5
4
  begin
6
- c = t ? Timeout.timeout(t) { $stdin.getch } : $stdin.getch
7
- rescue Timeout::Error
8
- return nil
9
- end
5
+ # 1) Read a byte (with optional timeout)
6
+ begin
7
+ c = t ? Timeout.timeout(t) { $stdin.getch } : $stdin.getch
8
+ rescue Timeout::Error
9
+ return nil
10
+ end
10
11
 
11
- # 2) If it's ESC, grab any quick trailing bytes
12
- seq = c
13
- if c == "\e"
14
- if IO.select([$stdin], nil, nil, 0.05)
15
- begin
16
- seq << $stdin.read_nonblock(16)
17
- rescue IO::WaitReadable, EOFError
12
+ # 2) If it's ESC, grab any quick trailing bytes
13
+ seq = c
14
+ if c == "\e"
15
+ if IO.select([$stdin], nil, nil, 0.05)
16
+ begin
17
+ seq << $stdin.read_nonblock(16)
18
+ rescue IO::WaitReadable, EOFError
19
+ end
18
20
  end
19
21
  end
20
- end
21
22
 
22
- # 3) Single ESC alone
23
- return "ESC" if seq == "\e"
23
+ # 3) Single ESC alone
24
+ return "ESC" if seq == "\e"
24
25
 
25
- # 4) Shift‑TAB
26
- return "S-TAB" if seq == "\e[Z"
26
+ # 4) Shift‑TAB
27
+ return "S-TAB" if seq == "\e[Z"
27
28
 
28
- # 5) Legacy single‑char shift‑arrows (your old working ones)
29
- case seq
30
- when "\e[a" then return "S-UP"
31
- when "\e[b" then return "S-DOWN"
32
- when "\e[c" then return "S-RIGHT"
33
- when "\e[d" then return "S-LEFT"
34
- end
29
+ # 5) Legacy single‑char shift‑arrows (your old working ones)
30
+ case seq
31
+ when "\e[a" then return "S-UP"
32
+ when "\e[b" then return "S-DOWN"
33
+ when "\e[c" then return "S-RIGHT"
34
+ when "\e[d" then return "S-LEFT"
35
+ end
35
36
 
36
- # 6) CSI style shift‑arrows (e.g. ESC [1;2A )
37
- if m = seq.match(/\A\e\[\d+;2([ABCD])\z/)
38
- return { 'A' => "S-UP", 'B' => "S-DOWN", 'C' => "S-RIGHT", 'D' => "S-LEFT" }[m[1]]
39
- end
37
+ # 6) CSI style shift‑arrows (e.g. ESC [1;2A )
38
+ if m = seq.match(/\A\e\[\d+;2([ABCD])\z/)
39
+ return { 'A' => "S-UP", 'B' => "S-DOWN", 'C' => "S-RIGHT", 'D' => "S-LEFT" }[m[1]]
40
+ end
40
41
 
41
- # 7) Plain arrows
42
- if m = seq.match(/\A\e\[([ABCD])\z/)
43
- return { 'A' => "UP", 'B' => "DOWN", 'C' => "RIGHT", 'D' => "LEFT" }[m[1]]
44
- end
42
+ # 7) Plain arrows
43
+ if m = seq.match(/\A\e\[([ABCD])\z/)
44
+ return { 'A' => "UP", 'B' => "DOWN", 'C' => "RIGHT", 'D' => "LEFT" }[m[1]]
45
+ end
45
46
 
46
- # 8) CSI + '~' sequences (Ins, Del, Home, End, PgUp, PgDn, F5-F12)
47
- if seq.start_with?("\e[") && seq.end_with?("~")
48
- num = seq[/\d+(?=~)/].to_i
49
- return case num
50
- when 1, 7 then "HOME"
51
- when 2 then "INS"
52
- when 3 then "DEL"
53
- when 4, 8 then "END"
54
- when 5 then "PgUP"
55
- when 6 then "PgDOWN"
56
- when 15 then "F5"
57
- when 17 then "F6"
58
- when 18 then "F7"
59
- when 19 then "F8"
60
- when 20 then "F9"
61
- when 21 then "F10"
62
- when 23 then "F11"
63
- when 24 then "F12"
64
- else ""
65
- end
66
- end
47
+ # 8) CSI + '~' sequences (Ins, Del, Home, End, PgUp, PgDn, F5-F12)
48
+ if seq.start_with?("\e[") && seq.end_with?("~")
49
+ num = seq[/\d+(?=~)/].to_i
50
+ return case num
51
+ when 1, 7 then "HOME"
52
+ when 2 then "INS"
53
+ when 3 then "DEL"
54
+ when 4, 8 then "END"
55
+ when 5 then "PgUP"
56
+ when 6 then "PgDOWN"
57
+ when 15 then "F5"
58
+ when 17 then "F6"
59
+ when 18 then "F7"
60
+ when 19 then "F8"
61
+ when 20 then "F9"
62
+ when 21 then "F10"
63
+ when 23 then "F11"
64
+ when 24 then "F12"
65
+ else ""
66
+ end
67
+ end
67
68
 
68
- # 9) SS3 function keys F1-F4
69
- if seq.start_with?("\eO") && seq.length == 3
70
- return case seq[2]
71
- when 'P' then "F1"
72
- when 'Q' then "F2"
73
- when 'R' then "F3"
74
- when 'S' then "F4"
75
- else ""
76
- end
77
- end
69
+ # 9) SS3 function keys F1-F4
70
+ if seq.start_with?("\eO") && seq.length == 3
71
+ return case seq[2]
72
+ when 'P' then "F1"
73
+ when 'Q' then "F2"
74
+ when 'R' then "F3"
75
+ when 'S' then "F4"
76
+ else ""
77
+ end
78
+ end
78
79
 
79
- # 10) Single / Ctrl-char mappings
80
- return case seq
81
- when "\r", "\n" then "ENTER"
82
- when "\t" then "TAB"
83
- when "\u007F", "\b" then "BACK"
84
- when "\u0000" then "C-SPACE"
85
- when "\u0001" then "C-A"
86
- when "\u0002" then "C-B"
87
- when "\u0003" then "C-C"
88
- when "\u0004" then "C-D"
89
- when "\u0005" then "C-E"
90
- when "\u0006" then "C-F"
91
- when "\u0007" then "C-G"
92
- when "\u0008" then "C-H"
93
- when "\u000B" then "C-K"
94
- when "\u000C" then "C-L"
95
- when "\u000D" then "C-M"
96
- when "\u000E" then "C-N"
97
- when "\u000F" then "C-O"
98
- when "\u0010" then "C-P"
99
- when "\u0011" then "C-Q"
100
- when "\u0012" then "C-R"
101
- when "\u0013" then "C-S"
102
- when "\u0014" then "C-T"
103
- when "\u0015" then "C-U"
104
- when "\u0016" then "C-V"
105
- when "\u0018" then "C-X"
106
- when "\u0019" then "C-Y"
107
- when "\u001A" then "C-Z"
108
- when "\u0017" then "WBACK"
109
- when /\A[[:print:]]\z/ then seq
110
- else ""
111
- end
80
+ # 10) Single / Ctrl-char mappings
81
+ return case seq
82
+ when "\r", "\n" then "ENTER"
83
+ when "\t" then "TAB"
84
+ when "\u007F", "\b" then "BACK"
85
+ when "\u0000" then "C-SPACE"
86
+ when "\u0001" then "C-A"
87
+ when "\u0002" then "C-B"
88
+ when "\u0003" then "C-C"
89
+ when "\u0004" then "C-D"
90
+ when "\u0005" then "C-E"
91
+ when "\u0006" then "C-F"
92
+ when "\u0007" then "C-G"
93
+ when "\u0008" then "C-H"
94
+ when "\u000B" then "C-K"
95
+ when "\u000C" then "C-L"
96
+ when "\u000D" then "C-M"
97
+ when "\u000E" then "C-N"
98
+ when "\u000F" then "C-O"
99
+ when "\u0010" then "C-P"
100
+ when "\u0011" then "C-Q"
101
+ when "\u0012" then "C-R"
102
+ when "\u0013" then "C-S"
103
+ when "\u0014" then "C-T"
104
+ when "\u0015" then "C-U"
105
+ when "\u0016" then "C-V"
106
+ when "\u0018" then "C-X"
107
+ when "\u0019" then "C-Y"
108
+ when "\u001A" then "C-Z"
109
+ when "\u0017" then "WBACK"
110
+ when /\A[[:print:]]\z/ then seq
111
+ else ""
112
+ end
113
+ ensure
114
+ if flush
115
+ while IO.select([$stdin], nil, nil, 0)
116
+ begin
117
+ $stdin.read_nonblock(4096)
118
+ rescue IO::WaitReadable, EOFError
119
+ break
120
+ end
121
+ end
122
+ end
123
+ end
112
124
  end
113
125
  end
114
126
  end
data/lib/rcurses/pane.rb CHANGED
@@ -342,7 +342,8 @@ module Rcurses
342
342
 
343
343
  def edit
344
344
  begin
345
- STDIN.raw!
345
+ STDIN.cooked! rescue nil
346
+ STDIN.echo = true rescue nil
346
347
  Rcurses::Cursor.show
347
348
  content = @text.pure.gsub("\n", "¬\n")
348
349
  @ix = 0
@@ -354,7 +355,7 @@ module Rcurses
354
355
  while input_char != 'ESC'
355
356
  row(@y + @line)
356
357
  col(@x + @pos)
357
- input_char = getchr
358
+ input_char = getchr(flush: false)
358
359
  case input_char
359
360
  when 'C-L'
360
361
  @align = 'l'
@@ -432,14 +433,19 @@ module Rcurses
432
433
  @txt = refresh(content)
433
434
  end
434
435
  ensure
435
- STDIN.cooked!
436
+ STDIN.raw! rescue nil
437
+ STDIN.echo = false rescue nil
438
+ while IO.select([$stdin], nil, nil, 0)
439
+ $stdin.read_nonblock(4096) rescue break
440
+ end
436
441
  end
437
442
  Rcurses::Cursor.hide
438
443
  end
439
444
 
440
445
  def editline
441
446
  begin
442
- STDIN.raw!
447
+ STDIN.cooked! rescue nil
448
+ STDIN.echo = true rescue nil
443
449
  Rcurses::Cursor.show
444
450
  @x = [[@x, 1].max, @max_w - @w + 1].min
445
451
  @y = [[@y, 1].max, @max_h - @h + 1].min
@@ -461,7 +467,7 @@ module Rcurses
461
467
  cont = cont.slice(0, content_len)
462
468
  print cont.ljust(content_len).c(fmt)
463
469
  col(@x + prompt_len + @pos)
464
- chr = getchr
470
+ chr = getchr(flush: false)
465
471
  case chr
466
472
  when 'LEFT'
467
473
  @pos -= 1 if @pos > 0
@@ -522,7 +528,11 @@ module Rcurses
522
528
  end
523
529
  end
524
530
  ensure
525
- STDIN.cooked!
531
+ STDIN.raw! rescue nil
532
+ STDIN.echo = false rescue nil
533
+ while IO.select([$stdin], nil, nil, 0)
534
+ $stdin.read_nonblock(4096) rescue break
535
+ end
526
536
  end
527
537
  Rcurses::Cursor.hide
528
538
  end
data/lib/rcurses.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Web_site: http://isene.com/
6
6
  # Github: https://github.com/isene/rcurses
7
7
  # License: Public domain
8
- # Version: 3.7.1: Fixed straggling residue key codes and improved clean_ansi
8
+ # Version: 3.7.3: Fixed pasting bug in edit(line)
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-17 00:00:00.000000000 Z
11
+ date: 2025-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -29,8 +29,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
29
29
  up text (in panes or anywhere in the terminal) in bold, italic, underline, reverse
30
30
  color, blink and in any 256 terminal colors for foreground and background. Use a
31
31
  simple editor to let users edit text in panes. Left, right or center align text
32
- in panes. Cursor movement around the terminal. New in 3.7.1: Fixed straggling residue
33
- key codes and improved clean_ansi.'
32
+ in panes. Cursor movement around the terminal. New in 3.7.3: Fixed pasting bug in
33
+ edit(line).'
34
34
  email: g@isene.com
35
35
  executables: []
36
36
  extensions: []