rcurses 2.4.5 → 2.4.7

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: 72fa40a32c3bd2d5b8d9b877570cef06ac7717923e5ceb00beb25ff604042d6f
4
- data.tar.gz: 4d98c839744b9715286ab94fe4d3f0e71c9c6ac2b755d9642b7ba2957c943200
3
+ metadata.gz: c3614072a43262fae0361e5fbca943f1e4da81a13a79b4bc2ea9ca7342d935c9
4
+ data.tar.gz: 4195f8f7ab5b5183f671487eb9df121a01db6991c4eafb5b5f81c19c0e190b12
5
5
  SHA512:
6
- metadata.gz: 530c8e9aa1f37ff1fabf89b70c03a6e572afddf6905d3a79d8c5a2f1e9f0ae582499e37168a9585b7e3ff0da1a49c6426e281fbc56d54884dd3cc610bd3575e9
7
- data.tar.gz: b9d7694f652427485d65317c931da8399139fdc25436e2526c91ef37b835bda2ed9ef7fe1a4652f9ba1dd6fe50ca3fdf42b7990b578617a3ebed0426868aa016
6
+ metadata.gz: c1f74c9ae9a72accf1b7cff35f772ca53b61bbc39f56dee8f190ead264fe6dc735e771bcac563832eae17b80452ea5b2098c63be6fbd20e386f18c3727112365
7
+ data.tar.gz: 06d521b146ed4962f5bd94d4c359bf8811ff1454ec6ede89e42ec2206fc32090186bf8bc8fc9df1acccdc0642f2cec2a5974656817969c76429d2b59f443b013
data/README.md CHANGED
@@ -85,6 +85,7 @@ move(x,y) | Move the pane by `x`and `y` (`mypane.move(-4,5)` will move the
85
85
  refresh | Refreshes/redraws the Pane with content
86
86
  edit | An editor for the Pane. When this is invoked, all existing font dressing is stripped and the user gets to edit the raw text. The user can add font effects similar to Markdown; Use an asterisk before and after text to be drawn in bold, text between forward-slashes become italic, and underline before and after text means the text will be underlined, a hash-sign before and after text makes the text reverse colored. You can also combine a whole set of dressings in this format: `<23,245,biurl|Hello World!>` - this will make "Hello World!" print in the color 23 with the background color 245 (regardless of the Pane's fg/bg setting) in bold, italic, underlined, reversed colored and blinking. Hitting `ESC` while in edit mode will disregard the edits, while `Ctrl-S` will save the edits
87
87
  editline | Used for one-line Panes. It will print the content of the property `prompt` and then the property `text` that can then be edited by the user. Hitting `ESC` will disregard the edits, while `ENTER` will save the edited text
88
+ ask(prompt,text) | Short form of setting panel.prompt, then panel.text and then doing a panel.editline
88
89
 
89
90
  # class String extensions
90
91
  Method extensions provided for the class String:
@@ -204,7 +205,7 @@ while $stdin.ready?
204
205
  chr += $stdin.getc
205
206
  end
206
207
  ```
207
- You can also pass two parameters to `getchr` with `getchr(min, time)` where `min` instructs getchr to wait for the minimum number of characters to return (not very useful) - and `time` is the timeout for waiting (can be very useful). You can happily call `getchr` without these parameters.
208
+ You can also pass a timeout to `getchr` with `getchr(time)` to wait for `time` number of seconds and returning `nil` if the user does not press a key.
208
209
 
209
210
 
210
211
  # Example
data/lib/rcurses/input.rb CHANGED
@@ -1,14 +1,21 @@
1
1
  module Rcurses
2
2
  module Input
3
- def getchr(m = nil, t = nil)
4
- # Function to process key presses
5
- c = $stdin.getch(min: m, time: t)
3
+ def getchr(t = nil)
4
+ # Wait for input up to t seconds; if none, return nil (or a timeout indicator)
5
+ if t && !IO.select([$stdin], nil, nil, t)
6
+ return nil
7
+ end
8
+
9
+ c = $stdin.getch
6
10
  case c
7
- when "\e" # ANSI escape sequences
8
- return "ESC" if !$stdin.ready?
11
+ when "\e"
12
+ # For escape sequences, use a very short timeout to check for extra bytes
13
+ unless IO.select([$stdin], nil, nil, 0.001)
14
+ return "ESC"
15
+ end
9
16
  second_char = $stdin.getc
10
17
  case second_char
11
- when '[' # CSI
18
+ when '['
12
19
  third_char = $stdin.getc
13
20
  case third_char
14
21
  when 'A' then chr = "UP"
@@ -34,16 +41,18 @@ module Rcurses
34
41
  when '4', '8'
35
42
  fourth_char = $stdin.getc
36
43
  chr = fourth_char == '~' ? "END" : ""
37
- else chr = ""
44
+ else
45
+ chr = ""
38
46
  end
39
- when 'O' # Function keys
47
+ when 'O'
40
48
  third_char = $stdin.getc
41
49
  case third_char
42
50
  when 'a' then chr = "C-UP"
43
51
  when 'b' then chr = "C-DOWN"
44
52
  when 'c' then chr = "C-RIGHT"
45
53
  when 'd' then chr = "C-LEFT"
46
- else chr = ""
54
+ else
55
+ chr = ""
47
56
  end
48
57
  else
49
58
  chr = ""
data/lib/rcurses/pane.rb CHANGED
@@ -13,6 +13,10 @@ module Rcurses
13
13
  @starty = starty.is_a?(Proc) ? starty : -> { starty }
14
14
  @width = width.is_a?(Proc) ? width : -> { width }
15
15
  @height = height.is_a?(Proc) ? height : -> { height }
16
+ @x = @startx.call
17
+ @y = @starty.call
18
+ @w = @width.call
19
+ @h = @height.call
16
20
  @fg, @bg = fg, bg
17
21
  @text = "" # Initialize text variable
18
22
  @align = "l" # Default alignment
@@ -28,6 +32,12 @@ module Rcurses
28
32
  refresh
29
33
  end
30
34
 
35
+ def ask(prompt, text)
36
+ @prompt = prompt
37
+ @text = text
38
+ editline
39
+ end
40
+
31
41
  def refresh(cont = @text)
32
42
  @max_h, @max_w = IO.console.winsize
33
43
 
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: 2.4.2: Added parameters 'min' and 'time' to getchr
8
+ # Version: 2.4.7: Fixed getchr timeout, added panel function 'ask'
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
@@ -60,10 +60,11 @@ class String
60
60
  result
61
61
  end
62
62
 
63
- # Injects the given string at the given visible character position.
64
- # A negative position is treated as an insertion at the end.
63
+ # Inserts the given substring at the provided visible character position.
64
+ # A negative position means insertion at the end.
65
+ # When inserting at the end and the string ends with an ANSI escape sequence,
66
+ # the insertion is placed before that trailing ANSI sequence.
65
67
  def inject(insertion, pos)
66
- # Work on visible text; if pos is negative, set it to the length (i.e. end).
67
68
  pure_text = self.pure
68
69
  visible_length = pure_text.length
69
70
  pos = visible_length if pos < 0
@@ -74,7 +75,7 @@ class String
74
75
  injected = false
75
76
 
76
77
  while i < self.length
77
- if self[i] == "\e" # ANSI escape sequence copy whole sequence without counting
78
+ if self[i] == "\e" # Start of an ANSI sequence.
78
79
  if m = self[i..-1].match(/\A(\e\[\d+(?:;\d+)*m)/)
79
80
  result << m[1]
80
81
  i += m[1].length
@@ -83,7 +84,6 @@ class String
83
84
  i += 1
84
85
  end
85
86
  else
86
- # At the point when we've output exactly pos visible characters, do the injection.
87
87
  if count == pos && !injected
88
88
  result << insertion
89
89
  injected = true
@@ -93,10 +93,18 @@ class String
93
93
  i += 1
94
94
  end
95
95
  end
96
- # In case pos equals the total visible length (i.e. insertion at the end) and
97
- # no injection has occurred inside the loop, append now.
98
- result << insertion unless injected
96
+
97
+ # If we haven't injected (i.e. pos equals visible_length),
98
+ # check for a trailing ANSI sequence and insert before it.
99
+ unless injected
100
+ if result =~ /(\e\[\d+(?:;\d+)*m)\z/
101
+ trailing = $1
102
+ result = result[0...-trailing.length] + insertion + trailing
103
+ else
104
+ result << insertion
105
+ end
106
+ end
107
+
99
108
  result
100
109
  end
101
110
  end
102
-
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: 2.4.5
4
+ version: 2.4.7
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-03-20 00:00:00.000000000 Z
11
+ date: 2025-03-22 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 2.4.5: Added functions ''shorten''
33
- and ''inject'' to the string class.'
32
+ in panes. Cursor movement around the terminal. New in 2.4.7: Fixed getchr timeout,
33
+ added panel function ''ask''.'
34
34
  email: g@isene.com
35
35
  executables: []
36
36
  extensions: []