terminal_rb 0.11.0 → 0.11.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: 82d95e0e2e8423c8bbb464019e8282bb589c5bc8fb02298ec529ff58e9ee67bb
4
- data.tar.gz: bbb98fffca9d97e21a5440644a1ddc0b91dc60e945af287da60dbab07b6ae63b
3
+ metadata.gz: cf8062e89f52459ef6bb5e6e61d6142986d43dbec76d223ab16656146e3467a1
4
+ data.tar.gz: 3656dd6c10b1c2a88697c485daa12d345cd48a128f7c63da92f97f1395780e8c
5
5
  SHA512:
6
- metadata.gz: 44d16eba18775b6bbd208d19288bd44265a30301607136cafb959e985e59248820829383dd714c62f235880d30c46f4ce0a86a46d46dd8b6f05e042f73068c20
7
- data.tar.gz: 80b0d17ece194d7fa8b36080314c21683bb1d7739344529bbf47c7da8afbc27c5c910a860393bf348edaef2a27e590d2b2505ab7d7d8934ae349eed152653144
6
+ metadata.gz: bc2fb13b0b73a329cc4d60c8af62c0e347b551e3ed3d72eac5be4fbbdd823830bc8410487145a49833d2c34f33c2a7d2d5f7bb250ad1608ed384a49f31a4e139
7
+ data.tar.gz: 874df65c622227f93c081a8d6ff26b18f380ab89a4ffbe76f38b23bc25c81ee33287179b0327c274d5e4a9c30abdf25ebac2fd535b6ea016da296b12d7cd7f14
@@ -28,14 +28,14 @@ module Terminal
28
28
  # ESC [ 1 ; <modifier> [~ABCDEFHPQRS]
29
29
  return if esc.size < 5
30
30
  key = @csi1[esc[-1].ord] or return
31
- return key if (mod = esc[3..-2].join.to_i - 1) < 1 # no mod
31
+ return key if (mod = esc[3..-2].join.to_i - 1) < 1
32
32
  (@mods.filter_map { |b, n| n if mod.allbits?(b) } << key).join('+')
33
33
  end
34
34
 
35
35
  def with_modifier(esc)
36
- return yield(esc[1..-2].join.to_i) if (idx = esc.index(';')).nil? # no mod
36
+ return yield(esc[1..-2].join.to_i) if (idx = esc.index(';')).nil?
37
37
  key = yield(esc[1..(idx - 1)].join.to_i) or return
38
- return key if (mod = esc[(idx + 1)..-2].join.to_i - 1) < 1 # no mod
38
+ return key if (mod = esc[(idx + 1)..-2].join.to_i - 1) < 1
39
39
  (@mods.filter_map { |b, n| n if mod.allbits?(b) } << key).join('+')
40
40
  end
41
41
  end
@@ -62,7 +62,15 @@ module Terminal
62
62
  0x15 => 'F10',
63
63
  0x17 => 'F11',
64
64
  0x18 => 'F12',
65
- 0x1b => 'Enter'
65
+ 0x19 => 'F13',
66
+ 0x1a => 'F14',
67
+ 0x1b => 'Enter',
68
+ 0x1c => 'F15',
69
+ 0x1d => 'F16',
70
+ 0x1f => 'F17',
71
+ 0x20 => 'F18',
72
+ 0x21 => 'F19',
73
+ 0x22 => 'F20'
66
74
  }.compare_by_identity.freeze
67
75
 
68
76
  @ss3 = {
@@ -33,7 +33,7 @@ module Terminal
33
33
  return if input_mode == :error
34
34
  return read_dumb(mode == :both) if @input_mode == :dumb
35
35
  return read_tty&.join if mode == :raw
36
- key, name = @input_mode == :csi_u ? read_csiu : read_legacy
36
+ key, name = read_tty_with(@input_mode == :csi_u ? CSIuKeys : LegacyKeys)
37
37
  return unless key
38
38
  mode == :both ? [key, name] : name || key
39
39
  end
@@ -48,42 +48,22 @@ module Terminal
48
48
  DumbKeys.key_name("\x05")
49
49
  end
50
50
 
51
- def read_legacy
51
+ def read_tty_with(trans)
52
52
  key, *esc = read_tty
53
53
  return unless key
54
- return key, LegacyKeys.key_name(key) if esc.empty?
55
- [key + esc.join, LegacyKeys.translate(esc)]
56
- end
57
-
58
- def read_csiu
59
- unless @csiu_set
60
- if _write("\e[>1u").nil?
61
- @input_mode = :legacy
62
- return read_legacy
63
- end
64
- @csiu_set = true
65
- at_exit { _write("\e[<u") if @csiu_set }
66
- end
67
- key, *esc = read_tty
68
- return unless key
69
- return key, CSIuKeys.key_name(key) if esc.empty?
70
- [key + esc.join, CSIuKeys.translate(esc)]
54
+ return key, trans.key_name(key) if esc.empty?
55
+ [key + esc.join, trans.translate(esc)]
71
56
  end
72
57
 
73
58
  def find_input_mode
74
- case ENV['INPUT_MODE']
75
- when 'dumb', 'DUMB'
76
- :dumb
77
- when 'legacy', 'LEGACY'
78
- :legacy
79
- when 'csi_u', 'CSI_U', 'csiu', 'CSIU'
59
+ im = ENV['INPUT_MODE']
60
+ return :dumb if im == 'dumb' || !STDIN.tty?
61
+ return :legacy if im == 'legacy'
62
+ if ansi? && _write("\e[>1u\e[?u\e[c") && csi_u?
63
+ at_exit { _write("\e[<u") }
80
64
  :csi_u
81
65
  else
82
- return :dumb unless STDIN.tty?
83
- STDIN.sync = true
84
- return :legacy if !ansi? || _write("\e[>1u\e[?u\e[c").nil? || !csi_u?
85
- _write("\e[<u")
86
- :csi_u
66
+ :legacy
87
67
  end
88
68
  rescue Interrupt
89
69
  :legacy
@@ -93,28 +73,25 @@ module Terminal
93
73
 
94
74
  def csi_u?
95
75
  # iTerm2 returns result in two chunks :/
96
- ret = false
76
+ found = false
97
77
  while true
98
- break if (str = STDIN.getch.dup) != "\e"
99
- while (nc = STDIN.read_nonblock(1, exception: false))
100
- String === nc ? str << nc : break
101
- end
102
- ret = true if str.include?("\e[?1u")
103
- break if str[-1] == 'c'
78
+ inp = read_tty&.join or return false
79
+ found = true if inp.include?("\e[?1u")
80
+ return found if inp[-1] == 'c'
104
81
  end
105
- ret
106
82
  end
107
83
 
108
- # nil, nil => error; key, [] => simple key; "\e", [] => esc sequence
109
84
  def read_tty
110
- key = [STDIN.getch]
111
- return key if key[0] != "\e"
112
- while (nc = STDIN.read_nonblock(1, exception: false))
113
- String === nc ? key << nc : break
85
+ STDIN.raw do |raw|
86
+ key = [raw.getch]
87
+ return key if key[0] != "\e"
88
+ while (nc = raw.read_nonblock(1, exception: false))
89
+ String === nc ? key << nc : break
90
+ end
91
+ key
114
92
  end
115
- key
116
93
  rescue Interrupt
117
- key
94
+ nil
118
95
  rescue IOError, SystemCallError
119
96
  @input_mode = :error
120
97
  nil
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Terminal
4
4
  # The version number of the gem.
5
- VERSION = '0.11.0'
5
+ VERSION = '0.11.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.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -49,7 +49,7 @@ metadata:
49
49
  rubygems_mfa_required: 'true'
50
50
  source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
51
51
  bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
52
- documentation_uri: https://rubydoc.info/gems/terminal_rb/0.11.0/Terminal
52
+ documentation_uri: https://rubydoc.info/gems/terminal_rb/0.11.1/Terminal
53
53
  rdoc_options: []
54
54
  require_paths:
55
55
  - lib