rcurses 2.4.2 → 2.4.6
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/README.md +2 -0
- data/lib/rcurses/pane.rb +4 -0
- data/lib/rcurses.rb +1 -1
- data/lib/string_extensions.rb +79 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f120b89280037a3485515b1cc75f7a08f122fde4faff32b2234b602bb37dbecf
|
4
|
+
data.tar.gz: 71aa736312930bf945f8af1e021430e4ff9ce23be9a12402a3ec046c272f5055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa2b26d81b024bd82cdeab5fc643072f4c4b1120cd96720a41926e5bafcc49c535b9df25242f534c99448a501000d3c30fd8331777f2eff03720472c3747182f
|
7
|
+
data.tar.gz: 2153244b482b08beb7234df2dd91fc542f438b6a814016ccdec68c32bd818e92744165bf10b87fa6a4d5167d30106a9bc7bcd4b259ab05eecb581112cbe8b2ab
|
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
|
|
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
|
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.
|
8
|
+
# Version: 2.4.6: Added x,y,w,h at panel creation, not just on refresh
|
9
9
|
|
10
10
|
require 'io/console' # Basic gem for rcurses
|
11
11
|
require 'io/wait' # stdin handling
|
data/lib/string_extensions.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class String
|
2
|
-
#
|
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")
|
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,77 @@ 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
|
+
# 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.
|
67
|
+
def inject(insertion, pos)
|
68
|
+
pure_text = self.pure
|
69
|
+
visible_length = pure_text.length
|
70
|
+
pos = visible_length if pos < 0
|
71
|
+
|
72
|
+
count = 0
|
73
|
+
result = ""
|
74
|
+
i = 0
|
75
|
+
injected = false
|
76
|
+
|
77
|
+
while i < self.length
|
78
|
+
if self[i] == "\e" # Start of an ANSI sequence.
|
79
|
+
if m = self[i..-1].match(/\A(\e\[\d+(?:;\d+)*m)/)
|
80
|
+
result << m[1]
|
81
|
+
i += m[1].length
|
82
|
+
else
|
83
|
+
result << self[i]
|
84
|
+
i += 1
|
85
|
+
end
|
86
|
+
else
|
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
|
+
|
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
|
+
|
108
|
+
result
|
109
|
+
end
|
34
110
|
end
|
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.
|
4
|
+
version: 2.4.6
|
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-
|
11
|
+
date: 2025-03-21 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.
|
33
|
-
|
32
|
+
in panes. Cursor movement around the terminal. New in 2.4.6: Added x,y,w,h at panel
|
33
|
+
creation, not just on refresh.'
|
34
34
|
email: g@isene.com
|
35
35
|
executables: []
|
36
36
|
extensions: []
|