rcurses 2.4.1 → 2.4.5

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: 7c231359439921bfa6f6da0d36db67cf20daf67054031b64b1362cf17a121f36
4
- data.tar.gz: 07af990392aca529a25aec404f3a92db948eb64dddd4811c8b9f6f80adca5d55
3
+ metadata.gz: 72fa40a32c3bd2d5b8d9b877570cef06ac7717923e5ceb00beb25ff604042d6f
4
+ data.tar.gz: 4d98c839744b9715286ab94fe4d3f0e71c9c6ac2b755d9642b7ba2957c943200
5
5
  SHA512:
6
- metadata.gz: c3d9d2f610c73f034474376e98aac7c63180e6ad1d224f8a0f57898ede77c37679548845b1d21e68f18aa59d187b64808ea417a3a1821b14a78041f35703c1f8
7
- data.tar.gz: 006b678e16cd6108fc615cb87e7d7937d88d1e556407e7258a6e6b68a9d0d911652277b8ece6e08f11e6479527b081d994d486dfcd72d9fed592ef6bb5995803
6
+ metadata.gz: 530c8e9aa1f37ff1fabf89b70c03a6e572afddf6905d3a79d8c5a2f1e9f0ae582499e37168a9585b7e3ff0da1a49c6426e281fbc56d54884dd3cc610bd3575e9
7
+ data.tar.gz: b9d7694f652427485d65317c931da8399139fdc25436e2526c91ef37b835bda2ed9ef7fe1a4652f9ba1dd6fe50ca3fdf42b7990b578617a3ebed0426868aa016
data/README.md CHANGED
@@ -101,6 +101,8 @@ l | Set text to be printed blinking (example: `"TEST".l`)
101
101
  r | Set text to be printed in reverse colors (example: `"TEST".r`)
102
102
  c(code) | Use coded format like "TEST".c("204,45,bui") to print "TEST" in bold, underline italic, fg=204 and bg=45 (the format is `.c("fg,bg,biulr"))
103
103
  pure | Strip text of any "dressing" (example: with `text = "TEST".b`, you will have bold text in the variable `text`, then with `text.pure` it will show "uncoded" or pure text)
104
+ shorten(n) | Shorten the pure version of the string to 'n' characters, preserving any ANSI coding
105
+ inject("chars",pos) | Inject "chars" at position 'pos' in the pure version of the string (if 'pos' is '-1', then append at end). Preserves any ANSI code
104
106
 
105
107
  PS: Blink does not work in conjunction with setting a background color in urxvt. It does work in gnome-terminal. But the overall performance in urxvt as orders of magnitude better than gnome-terminal.
106
108
 
@@ -121,8 +123,8 @@ up(n = 1) | Move cursor up by n (default is 1 character up)
121
123
  down(n = 1) | Move cursor down by n (default is 1 character down)
122
124
  left(n = 1) | Move cursor backward by n (default is one character)
123
125
  right(n = 1) | Move cursor forward by n (default is one character)
124
- next_line) | Move cursor down to beginning of next line
125
- prev_line) | Move cursor up to beginning of previous line
126
+ next_line | Move cursor down to beginning of next line
127
+ prev_line | Move cursor up to beginning of previous line
126
128
  clear_char(n = 1) | Erase n characters from the current cursor position (default is one character)
127
129
  clear_line | Erase the entire current line and return to beginning of the line
128
130
  clear_line_before | Erase from the beginning of the line up to and including the current cursor position
@@ -202,6 +204,8 @@ while $stdin.ready?
202
204
  chr += $stdin.getc
203
205
  end
204
206
  ```
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
+
205
209
 
206
210
  # Example
207
211
 
data/lib/rcurses/input.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Rcurses
2
2
  module Input
3
- def getchr
3
+ def getchr(m = nil, t = nil)
4
4
  # Function to process key presses
5
- c = $stdin.getch
5
+ c = $stdin.getch(min: m, time: t)
6
6
  case c
7
7
  when "\e" # ANSI escape sequences
8
8
  return "ESC" if !$stdin.ready?
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: Show cursor on edit. Changed hide_cursor and show_cursor to hide and show.
8
+ # Version: 2.4.2: Added parameters 'min' and 'time' to getchr
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
@@ -1,5 +1,5 @@
1
1
  class String
2
- # Add coloring to strings (with escaping for Readline)
2
+ # Existing methods...
3
3
  def fg(fg) ; color(self, "\e[38;5;#{fg}m", "\e[0m") ; end
4
4
  def bg(bg) ; color(self, "\e[48;5;#{bg}m", "\e[0m") ; end
5
5
  def fb(fg, bg); color(self, "\e[38;5;#{fg};48;5;#{bg}m"); end
@@ -8,10 +8,13 @@ class String
8
8
  def u ; color(self, "\e[4m", "\e[24m") ; end
9
9
  def l ; color(self, "\e[5m", "\e[25m") ; end
10
10
  def r ; color(self, "\e[7m", "\e[27m") ; end
11
+
11
12
  # Internal function
12
- def color(text, sp, ep = "\e[0m"); "#{sp}#{text}#{ep}"; end
13
+ def color(text, sp, ep = "\e[0m")
14
+ "#{sp}#{text}#{ep}"
15
+ end
13
16
 
14
- # Use format "TEST".c("204,45,bui") to print "TEST" in bold, underline italic, fg=204 and bg=45
17
+ # Use format "TEST".c("204,45,bui") to print "TEST" in bold, underline, italic, fg=204 and bg=45
15
18
  def c(code)
16
19
  prop = "\e["
17
20
  prop += "38;5;#{code.match(/^\d+/).to_s};" if code.match(/^\d+/)
@@ -31,4 +34,69 @@ class String
31
34
  def pure
32
35
  self.gsub(/\e\[\d+(?:;\d+)*m/, '')
33
36
  end
37
+
38
+ # Shortens the visible (pure) text to n characters, preserving any ANSI sequences.
39
+ def shorten(n)
40
+ count = 0
41
+ result = ""
42
+ i = 0
43
+ while i < self.length && count < n
44
+ if self[i] == "\e" # start of an ANSI escape sequence
45
+ if m = self[i..-1].match(/\A(\e\[\d+(?:;\d+)*m)/)
46
+ result << m[1]
47
+ i += m[1].length
48
+ else
49
+ # Fallback if pattern doesn’t match: treat as a normal character.
50
+ result << self[i]
51
+ i += 1
52
+ count += 1
53
+ end
54
+ else
55
+ result << self[i]
56
+ count += 1
57
+ i += 1
58
+ end
59
+ end
60
+ result
61
+ end
62
+
63
+ # Injects the given string at the given visible character position.
64
+ # A negative position is treated as an insertion at the end.
65
+ def inject(insertion, pos)
66
+ # Work on visible text; if pos is negative, set it to the length (i.e. end).
67
+ pure_text = self.pure
68
+ visible_length = pure_text.length
69
+ pos = visible_length if pos < 0
70
+
71
+ count = 0
72
+ result = ""
73
+ i = 0
74
+ injected = false
75
+
76
+ while i < self.length
77
+ if self[i] == "\e" # ANSI escape sequence – copy whole sequence without counting
78
+ if m = self[i..-1].match(/\A(\e\[\d+(?:;\d+)*m)/)
79
+ result << m[1]
80
+ i += m[1].length
81
+ else
82
+ result << self[i]
83
+ i += 1
84
+ end
85
+ else
86
+ # At the point when we've output exactly pos visible characters, do the injection.
87
+ if count == pos && !injected
88
+ result << insertion
89
+ injected = true
90
+ end
91
+ result << self[i]
92
+ count += 1
93
+ i += 1
94
+ end
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
99
+ result
100
+ end
34
101
  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.1
4
+ version: 2.4.5
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-12 00:00:00.000000000 Z
11
+ date: 2025-03-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 2.4: Show cursor on edit.
33
- Changed hide_cursor and show_cursor to hide and show. 2.4.1: Minor fixes'
32
+ in panes. Cursor movement around the terminal. New in 2.4.5: Added functions ''shorten''
33
+ and ''inject'' to the string class.'
34
34
  email: g@isene.com
35
35
  executables: []
36
36
  extensions: []