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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9933dc93d8bd52dd2cd910ecc126476fabe857f44d2ceb411d75ba1db5b6eec6
4
- data.tar.gz: 4eba28b0b33f775b0e941109529946b1c14b5bebeb09084d6ee69ea0663635c4
3
+ metadata.gz: cafdb9c85ec15ecd6a745f73d8b65379e20f9961b74be9a8dd8790b2162c6580
4
+ data.tar.gz: 825406bad23758d820de77588e4b2fa227e0aab72ba7ddb8fe6486bd9ffbffb7
5
5
  SHA512:
6
- metadata.gz: 50b7afe928e8d18e2159864cd646a0d5be3df82f456506682b061027e5bb047246e97dc22f04610cc2dc06091cb437e0b3bff713b4b3f4244f4b106df0cc6194
7
- data.tar.gz: 8f4d5c54bdb5dff79d6d588f9082455913a2c6081d9b6ebb8e575839375c05ecb0560d15a3b6b305cda5cdd10e22d0a2fe37772c4a7c67ac507fc0162509f756
6
+ metadata.gz: b27c798109a9e573dd3a126ea65768ccc444bd065eff36da13abfb64617cd5ef31c0904a4b6d81e1d7ddf586e66c9a55dec3a38aba350e2d2e1a27d9a3185444
7
+ data.tar.gz: f25439683ba4ed81b09166f47d622fc5d21ae84e7a836169657b0db116bafe9480407ddf30b0e0f689da4a0c6d102e923fb473be59f3276e69977aa3ed861584
data/lib/cli/ui/color.rb CHANGED
@@ -56,6 +56,7 @@ module CLI
56
56
  reset: RESET,
57
57
  bold: BOLD,
58
58
  gray: GRAY,
59
+ orange: ORANGE,
59
60
  }.freeze
60
61
 
61
62
  class InvalidColorName < ArgumentError
@@ -24,6 +24,7 @@ module CLI
24
24
  'magenta' => '35',
25
25
  'cyan' => '36',
26
26
  'gray' => '38;5;244',
27
+ 'orange' => '38;5;214',
27
28
  'white' => '97',
28
29
  'bold' => '1',
29
30
  'italic' => '3',
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
@@ -3,6 +3,6 @@
3
3
 
4
4
  module CLI
5
5
  module UI
6
- VERSION = '2.3.0'
6
+ VERSION = '2.4.0'
7
7
  end
8
8
  end
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.3.0
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: 2024-12-10 00:00:00.000000000 Z
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.0.3.1
105
- signing_key:
102
+ rubygems_version: 3.6.7
106
103
  specification_version: 4
107
104
  summary: Terminal UI framework
108
105
  test_files: []