cli-ui 2.3.0 → 2.4.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/lib/cli/ui/color.rb +1 -0
- data/lib/cli/ui/formatter.rb +1 -0
- data/lib/cli/ui/os.rb +3 -0
- data/lib/cli/ui/prompt/interactive_options.rb +63 -3
- data/lib/cli/ui/sorbet_runtime_stub.rb +0 -1
- data/lib/cli/ui/version.rb +1 -1
- data/lib/cli/ui.rb +2 -2
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cafdb9c85ec15ecd6a745f73d8b65379e20f9961b74be9a8dd8790b2162c6580
|
4
|
+
data.tar.gz: 825406bad23758d820de77588e4b2fa227e0aab72ba7ddb8fe6486bd9ffbffb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b27c798109a9e573dd3a126ea65768ccc444bd065eff36da13abfb64617cd5ef31c0904a4b6d81e1d7ddf586e66c9a55dec3a38aba350e2d2e1a27d9a3185444
|
7
|
+
data.tar.gz: f25439683ba4ed81b09166f47d622fc5d21ae84e7a836169657b0db116bafe9480407ddf30b0e0f689da4a0c6d102e923fb473be59f3276e69977aa3ed861584
|
data/lib/cli/ui/color.rb
CHANGED
data/lib/cli/ui/formatter.rb
CHANGED
data/lib/cli/ui/os.rb
CHANGED
@@ -46,6 +46,8 @@ module CLI
|
|
46
46
|
MAC
|
47
47
|
when /linux/
|
48
48
|
LINUX
|
49
|
+
when /freebsd/
|
50
|
+
FREEBSD
|
49
51
|
else
|
50
52
|
if RUBY_PLATFORM !~ /cygwin/ && ENV['OS'] == 'Windows_NT'
|
51
53
|
WINDOWS
|
@@ -58,6 +60,7 @@ module CLI
|
|
58
60
|
|
59
61
|
MAC = OS.new
|
60
62
|
LINUX = OS.new
|
63
|
+
FREEBSD = OS.new
|
61
64
|
WINDOWS = OS.new(emoji: false, color_prompt: false, arrow_keys: false, shift_cursor: true)
|
62
65
|
end
|
63
66
|
end
|
@@ -214,10 +214,45 @@ module CLI
|
|
214
214
|
@redraw = true
|
215
215
|
end
|
216
216
|
|
217
|
+
sig { void }
|
218
|
+
def first_option
|
219
|
+
@active = @filtered_options.first&.last || -1
|
220
|
+
@redraw = true
|
221
|
+
end
|
222
|
+
|
223
|
+
sig { void }
|
224
|
+
def last_option
|
225
|
+
@active = @filtered_options.last&.last || -1
|
226
|
+
@redraw = true
|
227
|
+
end
|
228
|
+
|
229
|
+
sig { void }
|
230
|
+
def next_page
|
231
|
+
active_index = @filtered_options.index { |_, num| num == @active } || 0
|
232
|
+
|
233
|
+
previous_visible = @filtered_options[active_index + max_lines]
|
234
|
+
previous_visible ||= @filtered_options.last
|
235
|
+
|
236
|
+
@active = previous_visible ? previous_visible.last : -1
|
237
|
+
@redraw = true
|
238
|
+
end
|
239
|
+
|
240
|
+
sig { void }
|
241
|
+
def previous_page
|
242
|
+
active_index = @filtered_options.index { |_, num| num == @active } || 0
|
243
|
+
|
244
|
+
# do not jump into the end of the options if the subtraction result is non-positive
|
245
|
+
previous_visible = @filtered_options[active_index - max_lines] if active_index - max_lines >= 0
|
246
|
+
previous_visible ||= @filtered_options.first
|
247
|
+
|
248
|
+
@active = previous_visible ? previous_visible.last : -1
|
249
|
+
@redraw = true
|
250
|
+
end
|
251
|
+
|
217
252
|
# n is 1-indexed selection
|
218
253
|
# n == 0 if "Done" was selected in @multiple mode
|
219
|
-
sig { params(n: Integer).void }
|
220
|
-
def select_n(n)
|
254
|
+
sig { params(n: Integer, final: T::Boolean).void }
|
255
|
+
def select_n(n, final: false)
|
221
256
|
if @multiple
|
222
257
|
if n == 0
|
223
258
|
@answer = []
|
@@ -230,6 +265,12 @@ module CLI
|
|
230
265
|
end
|
231
266
|
elsif n == 0
|
232
267
|
# Ignore pressing "0" when not in multiple mode
|
268
|
+
elsif !final && should_enter_select_mode?(n)
|
269
|
+
# When we have more than 9 options, we need to enter select mode
|
270
|
+
# to avoid pre-selecting (e.g) 1 when the user wanted 10.
|
271
|
+
# This also applies to 2 and 20+ options, 3/30+, etc.
|
272
|
+
start_line_select
|
273
|
+
@active = n
|
233
274
|
else
|
234
275
|
@active = n
|
235
276
|
@answer = n
|
@@ -237,6 +278,20 @@ module CLI
|
|
237
278
|
@redraw = true
|
238
279
|
end
|
239
280
|
|
281
|
+
sig { params(n: Integer).returns(T::Boolean) }
|
282
|
+
def should_enter_select_mode?(n)
|
283
|
+
# If we have less than 10 options, we don't need to enter select mode
|
284
|
+
# and we can just select the option directly. This just keeps the code easier
|
285
|
+
# by making the cases simpler to understand
|
286
|
+
return false if @options.length <= 9
|
287
|
+
|
288
|
+
# At this point we have 10+ options so always need to check if we should run.
|
289
|
+
# This can be simplified to checking if the length of options is >= to the option selected * 10:
|
290
|
+
# n == 1 && options.length >= 10 (1 * 10), n == 2 && options.length >= 20 (2 * 10), etc.
|
291
|
+
# which can be further simplified to just:
|
292
|
+
@options.length >= (n * 10)
|
293
|
+
end
|
294
|
+
|
240
295
|
sig { params(char: String).void }
|
241
296
|
def select_bool(char)
|
242
297
|
return unless (@options - ['yes', 'no']).empty?
|
@@ -282,7 +337,7 @@ module CLI
|
|
282
337
|
# Prevent selection of invisible options
|
283
338
|
return unless presented_options.any? { |_, num| num == @active }
|
284
339
|
|
285
|
-
select_n(@active)
|
340
|
+
select_n(@active, final: true)
|
286
341
|
end
|
287
342
|
|
288
343
|
sig { void }
|
@@ -343,6 +398,11 @@ module CLI
|
|
343
398
|
when 'B' ; down
|
344
399
|
when 'C' ; # Ignore right key
|
345
400
|
when 'D' ; # Ignore left key
|
401
|
+
when '3' ; print("\a")
|
402
|
+
when '5' ; previous_page
|
403
|
+
when '6' ; next_page
|
404
|
+
when 'H' ; first_option
|
405
|
+
when 'F' ; last_option
|
346
406
|
else ; raise Interrupt # unhandled escape sequence.
|
347
407
|
end
|
348
408
|
end
|
@@ -94,7 +94,6 @@ module T
|
|
94
94
|
def log_info_handler=(value); end
|
95
95
|
def scalar_types; end
|
96
96
|
def scalar_types=(values); end
|
97
|
-
# rubocop:disable Naming/InclusiveLanguage
|
98
97
|
def sealed_violation_whitelist; end
|
99
98
|
def sealed_violation_whitelist=(sealed_violation_whitelist); end
|
100
99
|
# rubocop:enable Naming/InclusiveLanguage
|
data/lib/cli/ui/version.rb
CHANGED
data/lib/cli/ui.rb
CHANGED
@@ -404,10 +404,10 @@ module CLI
|
|
404
404
|
end
|
405
405
|
end
|
406
406
|
|
407
|
-
self.enable_color = $stdout.tty?
|
407
|
+
self.enable_color = T.must($stdout.tty? && ENV['TERM'] != 'dumb')
|
408
408
|
|
409
409
|
# Shopify's CI system supports color, but not cursor control
|
410
|
-
self.enable_cursor = T.must($stdout.tty? && ENV['CI'].nil? && ENV['JOURNAL_STREAM'].nil?)
|
410
|
+
self.enable_cursor = T.must($stdout.tty? && ENV['TERM'] != 'dumb' && ENV['CI'].nil? && ENV['JOURNAL_STREAM'].nil?)
|
411
411
|
end
|
412
412
|
end
|
413
413
|
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burke Libbey
|
8
8
|
- Julian Nadeau
|
9
9
|
- Lisa Ugray
|
10
|
-
autorequire:
|
11
10
|
bindir: exe
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: minitest
|
@@ -86,7 +85,6 @@ homepage: https://github.com/shopify/cli-ui
|
|
86
85
|
licenses:
|
87
86
|
- MIT
|
88
87
|
metadata: {}
|
89
|
-
post_install_message:
|
90
88
|
rdoc_options: []
|
91
89
|
require_paths:
|
92
90
|
- lib
|
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
99
|
- !ruby/object:Gem::Version
|
102
100
|
version: '0'
|
103
101
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
-
signing_key:
|
102
|
+
rubygems_version: 3.6.7
|
106
103
|
specification_version: 4
|
107
104
|
summary: Terminal UI framework
|
108
105
|
test_files: []
|