terminal_rb 0.9.0 → 0.9.1

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: 351b0ba282f1686000796ca789653308c722d201286ea7e1e6b99d2802db2b21
4
- data.tar.gz: c25af6f120fc06e991b7f2a5f616141ac44d99a72a7d4569228d7822daa730a4
3
+ metadata.gz: 8fdd6ab56d007f6fa6e82bf8d557d0a27815ad789998da5583310dd62af2b551
4
+ data.tar.gz: ef83edfd6c82bc9a2a056d148cd4da2af7b1a28acaa0cab9863901d608d502b7
5
5
  SHA512:
6
- metadata.gz: 31c49a47f6bf38aa08cb8e75e85fe5180d7d676b737392b38e52baebf1ff7669d9fb76d1037bfdb1e13a5683b36a434e41b4001ef2dfc56692ed1229cc7f044d
7
- data.tar.gz: 2ba822e7bc9448d577f6f6649abb8b6c8f6fb9c44a76c86d9c9595c78cfd96e9dbda1451d6617e5c180e19a1c40dd0b7b09392fc1894dd3dbe858b7ab526c6da
6
+ metadata.gz: d53c04af3d74273cf3111b9b7078846e0c33f0caf8501e9f0182427ed784d96b94444c1f6238427dd248cf300fb362d95a3a0f5dea2ead5c571ff2fd7d52fdf9
7
+ data.tar.gz: 82d79cfab6b7d499bb5d6f9fb7d6ce9af14f69ed792f8f7eedf4485a4f26546576ecadd723cc67a48ffbb4bc00ab1cc83d04a15a1bceb37d8437ec825d0f38cc
data/README.md CHANGED
@@ -4,7 +4,7 @@ Terminal access with support for ANSI control codes and [BBCode-like](https://en
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/terminal_rb)
6
6
  - Source: [codeberg.org](https://codeberg.org/mblumtritt/Terminal.rb)
7
- - Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/Terminal)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/0.9.0/Terminal)
8
8
 
9
9
  ## Features
10
10
 
@@ -43,6 +43,22 @@ Terminal::Text.width('ライブラリは中国語、日本語、韓国語のテ
43
43
  # => 64
44
44
  ```
45
45
 
46
+ ### Split text word-wise and limit line width to 30 chars
47
+
48
+ ```ruby
49
+ Terminal::Text.each_line(<<~TEXT, limit: 30).to_a
50
+ [b]Hello Ruby World![/]
51
+ This gem provides terminal access with support for [i]ANSI[/] control codes
52
+ and [i]BBCode-like[/] embedded text attribute syntax.
53
+ TEXT
54
+ # => ["\e[1mHello Ruby World!\e[m",
55
+ # => "This gem provides terminal",
56
+ # => "access with support for \e[3mANSI\e[m",
57
+ # => "control codes",
58
+ # => "and \e[3mBBCode-like\e[m embedded text",
59
+ # => "attribute syntax."]
60
+ ```
61
+
46
62
  Have a look at the [examples](./examples/) directory to learn from code.
47
63
 
48
64
  ## Installation
@@ -47,47 +47,37 @@ module Terminal
47
47
  KEY_MAP =
48
48
  Module
49
49
  .new do
50
- def self.add_modifiers(**keys)
50
+ def self.add_modifiers(keys)
51
51
  @mods.each_pair do |mod, pref|
52
- @map.merge!(
53
- keys.to_h do |name, code|
54
- ["\e[1;#{mod}#{code}", "#{pref}+#{name}"]
55
- end
56
- )
52
+ keys.each_pair do |name, code|
53
+ @map["\e[1;#{mod}#{code}"] = "#{pref}+#{name}"
54
+ end
57
55
  end
58
56
  end
59
57
 
60
- def self.add_keys(**keys)
61
- @map.merge!(keys.to_h { |name, code| ["\e[#{code}", name] })
62
- add_modifiers(**keys)
58
+ def self.add_keys(keys)
59
+ keys.each_pair { |name, code| @map["\e[#{code}"] = name }
60
+ add_modifiers(keys)
63
61
  end
64
62
 
65
- def self.add_fkeys(**keys)
66
- @map.merge!(keys.to_h { |name, code| ["\e[#{code}~", name] })
63
+ def self.add_fkeys(keys)
64
+ keys.each_pair { |name, code| @map["\e[#{code}~"] = name }
67
65
  @mods.each_pair do |mod, prefix|
68
- @map.merge!(
69
- keys.to_h do |name, code|
70
- ["\e[#{code};#{mod}~", "#{prefix}+#{name}"]
71
- end
72
- )
73
- end
74
- end
75
-
76
- def self.add_alt_keys(**keys)
77
- keys.each_pair do |name, code|
78
- @map[code] = name
79
- @map["\e#{code}"] = "Alt+#{name}" # kitty
66
+ keys.each_pair do |name, code|
67
+ @map["\e[#{code};#{mod}~"] = "#{prefix}+#{name}"
68
+ end
80
69
  end
81
70
  end
82
71
 
83
72
  def self.to_hash
84
- # control codes
85
73
  num = 0
86
74
  @map = ('A'..'Z').to_h { [(num += 1).chr, "Ctrl+#{_1}"] }
87
75
 
88
- add_keys('F1' => 'P', 'F2' => 'Q', 'F3' => 'R', 'F4' => 'S')
89
-
90
76
  add_keys(
77
+ 'F1' => 'P',
78
+ 'F2' => 'Q',
79
+ 'F3' => 'R',
80
+ 'F4' => 'S',
91
81
  'Up' => 'A',
92
82
  'Down' => 'B',
93
83
  'Right' => 'C',
@@ -97,7 +87,7 @@ module Terminal
97
87
  )
98
88
 
99
89
  add_fkeys(
100
- 'DEL' => '3',
90
+ 'Del' => '3',
101
91
  'PgUp' => '5',
102
92
  'PgDown' => '6',
103
93
  # -
@@ -126,18 +116,29 @@ module Terminal
126
116
 
127
117
  add_fkeys('F3' => '13') # Kitty
128
118
 
129
- add_alt_keys(
130
- 'ESC' => "\e",
131
- 'ENTER' => "\r",
132
- 'TAB' => "\t",
133
- 'BACK' => "\u007F",
134
- 'Ctrl+BACK' => "\b",
135
- 'Shift+TAB' => "\e[Z"
136
- )
119
+ # Kitty:
120
+ @mods.each_pair do |mod, pref|
121
+ ('a'..'z').each do |char|
122
+ @map["\e[#{char.ord};#{mod}u"] = "#{pref}+#{char.upcase}"
123
+ end
124
+ end
125
+
126
+ {
127
+ 'Esc' => "\e",
128
+ 'Enter' => "\r",
129
+ 'Tab' => "\t",
130
+ 'Back' => "\u007F",
131
+ 'Shift+Tab' => "\e[Z"
132
+ }.each_pair do |name, code|
133
+ @map[code] = name
134
+ @map["\e#{code}"] = "Alt+#{name}" # Kitty
135
+ end
137
136
 
138
137
  # overrides and additional keys
139
138
  @map.merge!(
140
- "\4" => 'DEL',
139
+ "\b" => 'Ctrl+Back',
140
+ "\e\b" => 'Ctrl+Alt+Back', # Kitty
141
+ "\4" => 'Del',
141
142
  "\e[5" => 'PgUp',
142
143
  "\e[6" => 'PgDown',
143
144
  # SS3 control (VT 100 etc)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Terminal
4
4
  # The version number of the gem.
5
- VERSION = '0.9.0'
5
+ VERSION = '0.9.1'
6
6
  end
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.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -44,10 +44,10 @@ homepage: https://codeberg.org/mblumtritt/Terminal.rb
44
44
  licenses:
45
45
  - MIT
46
46
  metadata:
47
+ rubygems_mfa_required: 'true'
47
48
  source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
48
49
  bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
49
- documentation_uri: https://rubydoc.info/gems/terminal_rb/Terminal
50
- rubygems_mfa_required: 'true'
50
+ documentation_uri: https://rubydoc.info/gems/terminal_rb/0.9.1/Terminal
51
51
  rdoc_options: []
52
52
  require_paths:
53
53
  - lib