rcurses 2.4.2 → 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 +4 -4
- data/README.md +2 -0
- data/lib/string_extensions.rb +71 -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: 72fa40a32c3bd2d5b8d9b877570cef06ac7717923e5ceb00beb25ff604042d6f
|
4
|
+
data.tar.gz: 4d98c839744b9715286ab94fe4d3f0e71c9c6ac2b755d9642b7ba2957c943200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
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,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.
|
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-
|
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.
|
33
|
-
and ''
|
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: []
|