cli-ui 2.3.1 → 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: 99ed2ae4a35b13db165864297acf7cfc4e636283e51683a7954ca2e2f43ac94c
4
- data.tar.gz: 30eb1a74cdbd50b95d9c48209c97258261970c9678eb71e089bb894a018bcb0b
3
+ metadata.gz: cafdb9c85ec15ecd6a745f73d8b65379e20f9961b74be9a8dd8790b2162c6580
4
+ data.tar.gz: 825406bad23758d820de77588e4b2fa227e0aab72ba7ddb8fe6486bd9ffbffb7
5
5
  SHA512:
6
- metadata.gz: 219e73a9baa10649b9cd14280ce9fe8d2f18a614006c9b4f5c8c79b3df3da3ef236c00ec290816ab866ff3d67cf058ecf5c88f0034e331a1ab77cdef1df25111
7
- data.tar.gz: 79de546a04f2ca9fe49246be7df31582cafc791799bbacd868af7fa1e381e42a462685e619a734745500203a25587a7eb6eaee04465b269cee8242ad67334a1b
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,7 +265,7 @@ module CLI
230
265
  end
231
266
  elsif n == 0
232
267
  # Ignore pressing "0" when not in multiple mode
233
- elsif should_enter_select_mode?(n)
268
+ elsif !final && should_enter_select_mode?(n)
234
269
  # When we have more than 9 options, we need to enter select mode
235
270
  # to avoid pre-selecting (e.g) 1 when the user wanted 10.
236
271
  # This also applies to 2 and 20+ options, 3/30+, etc.
@@ -302,7 +337,7 @@ module CLI
302
337
  # Prevent selection of invisible options
303
338
  return unless presented_options.any? { |_, num| num == @active }
304
339
 
305
- select_n(@active)
340
+ select_n(@active, final: true)
306
341
  end
307
342
 
308
343
  sig { void }
@@ -363,6 +398,11 @@ module CLI
363
398
  when 'B' ; down
364
399
  when 'C' ; # Ignore right key
365
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
366
406
  else ; raise Interrupt # unhandled escape sequence.
367
407
  end
368
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.1'
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.1
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: 2025-03-17 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.5.9
105
- signing_key:
102
+ rubygems_version: 3.6.7
106
103
  specification_version: 4
107
104
  summary: Terminal UI framework
108
105
  test_files: []