cli_class_tool 2.0.0 → 2.1.0
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/CHANGELOG +7 -0
- data/README.md +19 -0
- data/lib/cli_class_tool/string.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89e584d14bafdaf918d35406f8bf1dd1b548147cf65ff7e8a51f0f687add515c
|
|
4
|
+
data.tar.gz: 4dc4ed8c9a27d01fdf8b3cc408532b42e0c7ab2c80b6e75d92b35c1a200be4bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52e76102055a0d40a7ef754232f30619a882b906200d29e7a31eafe87e24304225bc022877c3a504957389064874046ee522aba7d7e96d3dee46697d6e7afdaf
|
|
7
|
+
data.tar.gz: be038285b90077978d9b4f72150d66aee2d994f9dffa6b709b59c49b1be8a645a0fcfe1b9f6ca2e1cf9ffe372c1ad9832be7aa7ea026353c33084797e1bd1f3e
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
------------------
|
|
2
|
+
2.1.0 (2026-09-25)
|
|
3
|
+
------------------
|
|
4
|
+
|
|
5
|
+
* Add `String#hyperlink` method for OSC 8 terminal hyperlinks
|
|
6
|
+
* Add `String#visible_length` method to compute visible string length stripped of ANSI escapes, control characters, and hyperlinks
|
|
7
|
+
|
|
1
8
|
------------------
|
|
2
9
|
2.0.0 (2026-09-18)
|
|
3
10
|
------------------
|
data/README.md
CHANGED
|
@@ -488,3 +488,22 @@ puts "System Message".bold # Bold text using default terminal color
|
|
|
488
488
|
```
|
|
489
489
|
|
|
490
490
|
These methods automatically check if `$stdout` is a TTY and safely fall back to standard, unformatted strings if output is piped or redirected (non-TTY mode).
|
|
491
|
+
|
|
492
|
+
### Terminal Hyperlinks (`hyperlink`)
|
|
493
|
+
|
|
494
|
+
You can create clickable OSC 8 terminal hyperlinks using the `.hyperlink(url)` method. When `$stdout` is a TTY and a target URL is provided, it formats the string with OSC 8 escape sequences; otherwise, it returns the original string:
|
|
495
|
+
|
|
496
|
+
```ruby
|
|
497
|
+
puts "Visit Website".hyperlink("https://example.com")
|
|
498
|
+
puts "Source Code".blue.hyperlink("https://github.com")
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Visible String Length (`visible_length`)
|
|
502
|
+
|
|
503
|
+
To compute the display length of a string without ANSI color escape codes, embedded hyperlinks, or residual control characters, use `.visible_length`:
|
|
504
|
+
|
|
505
|
+
```ruby
|
|
506
|
+
str = "Click here".bold.red.hyperlink("https://example.com")
|
|
507
|
+
str.length # Raw string length including escape sequences
|
|
508
|
+
str.visible_length # 10 (visible characters count)
|
|
509
|
+
```
|
|
@@ -139,4 +139,28 @@ class String
|
|
|
139
139
|
def light_white
|
|
140
140
|
colorize(97)
|
|
141
141
|
end
|
|
142
|
+
|
|
143
|
+
# Wrap the string in an OSC 8 terminal hyperlink if stdout is a TTY.
|
|
144
|
+
#
|
|
145
|
+
# @param url [String, #to_s, nil] Target URL for the hyperlink.
|
|
146
|
+
# @return [String] The formatted terminal hyperlink, or original string if not a TTY or URL is nil/empty.
|
|
147
|
+
def hyperlink(url)
|
|
148
|
+
@@is_a_tty = $stdout.isatty() if @@is_a_tty == nil
|
|
149
|
+
if @@is_a_tty && url && !url.to_s.empty?
|
|
150
|
+
"\e]8;;#{url}\e\\#{self}\e]8;;\e\\"
|
|
151
|
+
else
|
|
152
|
+
self
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Compute the visible length of the string
|
|
157
|
+
# Without any of ANSI/ASCII control characters nor embedded hyperlinks
|
|
158
|
+
#
|
|
159
|
+
# @return [Integer] Visible string length
|
|
160
|
+
def visible_length()
|
|
161
|
+
return self.gsub(/\e\]8;.*?(?:\e\\|\a)/, "") # Removes opening and closing hyperlink tags
|
|
162
|
+
.gsub(/\e\[[0-9;?]*[a-zA-Z]/, "") # Removes ANSI escape codes (colors, cursor control)
|
|
163
|
+
.gsub(/[[:cntrl:]]/, "") # Removes any residual control characters
|
|
164
|
+
.length
|
|
165
|
+
end
|
|
142
166
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cli_class_tool
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolas Morey
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-09-
|
|
10
|
+
date: 2026-09-25 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rake
|