terminal_rb 0.6.0 → 0.7.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/README.md +14 -3
- data/examples/info.rb +5 -5
- data/lib/terminal/detect.rb +21 -20
- data/lib/terminal/text.rb +9 -2
- data/lib/terminal/version.rb +1 -1
- data/lib/terminal.rb +2 -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: f0ee278f7b96ba33953b258b8ca66365bbd3e97ea670488711e8ad42aa3e59b3
|
4
|
+
data.tar.gz: de6c7769a32cf5aef25cf8acd055b1e86a5ac5b80eb36ff71afa83eba057f083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c9198faea2f62bb289f19c3a42c8d271b898b826b1990164bea6eead69b1f78324ec02cc408b3d35a40b915de7e9e59b5d43489971c4ec6222a36a55b4a202
|
7
|
+
data.tar.gz: f61cb0793edf2b27b9455e14df9ee5604c142f72e078cde13655fff055d626d0b3d9566dea2f029954c8b298a1c278af9f6612de4fded640dd1a3c17b7ae2f4d
|
data/README.md
CHANGED
@@ -19,17 +19,28 @@ Terminal access with support for ANSI control codes and [BBCode-like](https://en
|
|
19
19
|
|
20
20
|
## Examples
|
21
21
|
|
22
|
-
### Check
|
22
|
+
### Check whether ANSI is supported
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
Terminal.ansi?
|
26
26
|
# => true when current terminal emulator supports ANSI control codes
|
27
27
|
```
|
28
28
|
|
29
|
-
### Print
|
29
|
+
### Print embedded formatting
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
Terminal.puts "[red on_bright_yellow bold]Hello World![/]"
|
33
|
+
# when terminal supports ANSI
|
34
|
+
# => prints "\e[31;103;1mHello World!\e[m"
|
35
|
+
# when terminal does not support ANSI
|
36
|
+
# => prints "Hello World"
|
37
|
+
```
|
38
|
+
|
39
|
+
### Calculate display width of a string
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Terminal::Text.width('ライブラリは中国語、日本語、韓国語のテキストをサポートしています')
|
43
|
+
# => 64
|
33
44
|
```
|
34
45
|
|
35
46
|
Have a look at the [examples](./examples/) directory to learn from code.
|
@@ -42,7 +53,7 @@ You can install the gem in your system with
|
|
42
53
|
gem install terminal_rb
|
43
54
|
```
|
44
55
|
|
45
|
-
or you can use [Bundler](http://gembundler.com/) to add Terminal to your own project:
|
56
|
+
or you can use [Bundler](http://gembundler.com/) to add Terminal.rb to your own project:
|
46
57
|
|
47
58
|
```shell
|
48
59
|
bundle add terminal_rb
|
data/examples/info.rb
CHANGED
@@ -6,10 +6,10 @@ Terminal.puts <<~TEXT
|
|
6
6
|
|
7
7
|
✅ [b bright_green]Terminal.rb[/b] — Terminal Info:[/]
|
8
8
|
|
9
|
-
Ansi mode: #{Terminal.ansi? ? '✓' : '𐄂'}
|
10
|
-
Application: #{Terminal.application}
|
11
|
-
Supported Colors: #{Terminal.colors}#{' (truecolor)' if Terminal.true_color?}
|
12
|
-
Terminal Size: #{Terminal.size.join(' x ')}
|
13
|
-
Cursor Position: #{Terminal.pos
|
9
|
+
Ansi mode: #{Terminal.ansi? ? '[b bright_green]✓' : '[b bright_red]𐄂'}[/]
|
10
|
+
Application: [b bright_blue]#{Terminal.application}[/]
|
11
|
+
Supported Colors: [b]#{Terminal.colors}#{Terminal::Ansi.rainbow(' (truecolor)') if Terminal.true_color?}[/]
|
12
|
+
Terminal Size: [b]#{Terminal.size.join(' x ')}[/]
|
13
|
+
Cursor Position: [b]#{Terminal.pos&.join(', ')}[/]
|
14
14
|
|
15
15
|
TEXT
|
data/lib/terminal/detect.rb
CHANGED
@@ -5,31 +5,26 @@ module Terminal
|
|
5
5
|
class << self
|
6
6
|
def application
|
7
7
|
return :kitty if ENV.key?('KITTY_PID')
|
8
|
+
return :alacritty if ENV.key?('ALACRITTY_WINDOW_ID')
|
8
9
|
app_from_term_program || app_from_term
|
9
10
|
end
|
10
11
|
|
11
12
|
def colors
|
12
|
-
|
13
|
-
|
14
|
-
16_777_216
|
13
|
+
if KNOW_APP_WITH_TRUE_COLOR.include?(app_from_term_program) ||
|
14
|
+
(ENV['COLORTERM'] == 'truecolor')
|
15
|
+
return 16_777_216
|
16
|
+
end
|
17
|
+
term = ENV['TERM'] or return 8
|
18
|
+
return 16_777_216 if /[+-]direct/.match?(term)
|
19
|
+
match = /[-+](\d+)color/.match(term) and return match[1].to_i
|
20
|
+
match = /[-+](\d+)bit/.match(term) and return 2**match[1].to_i
|
21
|
+
ret = color_by_name[term] and return ret
|
22
|
+
case term
|
23
|
+
when /^(?:iTerm\s?\d*\.app|nsterm-build\d+|terminology(-[0-9.]+)?)$/
|
24
|
+
256
|
25
|
+
when /^(?:dg\+ccc|dgunix\+ccc|d430.*?[-+](?:dg|unix).*?[-+]ccc)$/
|
26
|
+
52
|
15
27
|
else
|
16
|
-
term = ENV['TERM'] or return 8
|
17
|
-
return 16_777_216 if /[+-]direct/.match?(term)
|
18
|
-
match = /[-+](\d+)color/.match(term) and return match[1].to_i
|
19
|
-
match = /[-+](\d+)bit/.match(term) and return 2**match[1].to_i
|
20
|
-
ret = color_by_name[term] and return ret
|
21
|
-
if /^(
|
22
|
-
iTerm\s?\d*\.app
|
23
|
-
|nsterm-build\d+
|
24
|
-
|terminology(-[0-9.]+)?
|
25
|
-
)$/x.match?(
|
26
|
-
term
|
27
|
-
)
|
28
|
-
return 256
|
29
|
-
end
|
30
|
-
if /^(dg+ccc|dgunix+ccc|d430.*?[-+](dg|unix).*?[-+]ccc)$/.match?(term)
|
31
|
-
return 52
|
32
|
-
end
|
33
28
|
8
|
34
29
|
end
|
35
30
|
end
|
@@ -46,6 +41,8 @@ module Terminal
|
|
46
41
|
'Hyper' => :hyper,
|
47
42
|
'HyperTerm' => :hyper,
|
48
43
|
'iTerm.app' => :iterm,
|
44
|
+
'rio' => :rio,
|
45
|
+
'Tabby' => :tabby,
|
49
46
|
'Terminus' => :terminus,
|
50
47
|
'tmux' => :tmux,
|
51
48
|
'vscode' => :vscode,
|
@@ -79,6 +76,7 @@ module Terminal
|
|
79
76
|
'wy370' => :wyse,
|
80
77
|
'xnuppc' => :xnuppc
|
81
78
|
}.each_pair { |str, type| return type if value.start_with?(str) }
|
79
|
+
nil
|
82
80
|
end
|
83
81
|
|
84
82
|
def color_by_name
|
@@ -144,6 +142,9 @@ module Terminal
|
|
144
142
|
'dummy' => 2
|
145
143
|
}
|
146
144
|
end
|
145
|
+
|
146
|
+
KNOW_APP_WITH_TRUE_COLOR = %i[kitty ghostty vscode iterm].freeze
|
147
|
+
private_constant :KNOW_APP_WITH_TRUE_COLOR
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
data/lib/terminal/text.rb
CHANGED
@@ -37,7 +37,14 @@ module Terminal
|
|
37
37
|
width
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
40
|
+
# Iterate each line of given text.
|
41
|
+
# It can optionally
|
42
|
+
#
|
43
|
+
# - interprete embedded BBCode
|
44
|
+
# - remove ANSI control codes
|
45
|
+
# - ignore embedded new line
|
46
|
+
# - limit text output width
|
47
|
+
# - report each line's size
|
41
48
|
#
|
42
49
|
# @param (see Wrap#initialize)
|
43
50
|
# @param (see Wrap#each_line)
|
@@ -110,7 +117,7 @@ module Terminal
|
|
110
117
|
end
|
111
118
|
end
|
112
119
|
|
113
|
-
#
|
120
|
+
# Iterate each line of given text.
|
114
121
|
#
|
115
122
|
# @param [#to_i, nil] limit
|
116
123
|
# optionally limit line size
|
data/lib/terminal/version.rb
CHANGED
data/lib/terminal.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
@@ -46,7 +46,7 @@ licenses:
|
|
46
46
|
metadata:
|
47
47
|
source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
|
48
48
|
bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
|
49
|
-
documentation_uri: https://rubydoc.info/gems/terminal_rb
|
49
|
+
documentation_uri: https://rubydoc.info/gems/terminal_rb/Terminal
|
50
50
|
rubygems_mfa_required: 'true'
|
51
51
|
rdoc_options: []
|
52
52
|
require_paths:
|