cli-ui 2.3.0 → 2.3.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: 9933dc93d8bd52dd2cd910ecc126476fabe857f44d2ceb411d75ba1db5b6eec6
4
- data.tar.gz: 4eba28b0b33f775b0e941109529946b1c14b5bebeb09084d6ee69ea0663635c4
3
+ metadata.gz: 99ed2ae4a35b13db165864297acf7cfc4e636283e51683a7954ca2e2f43ac94c
4
+ data.tar.gz: 30eb1a74cdbd50b95d9c48209c97258261970c9678eb71e089bb894a018bcb0b
5
5
  SHA512:
6
- metadata.gz: 50b7afe928e8d18e2159864cd646a0d5be3df82f456506682b061027e5bb047246e97dc22f04610cc2dc06091cb437e0b3bff713b4b3f4244f4b106df0cc6194
7
- data.tar.gz: 8f4d5c54bdb5dff79d6d588f9082455913a2c6081d9b6ebb8e575839375c05ecb0560d15a3b6b305cda5cdd10e22d0a2fe37772c4a7c67ac507fc0162509f756
6
+ metadata.gz: 219e73a9baa10649b9cd14280ce9fe8d2f18a614006c9b4f5c8c79b3df3da3ef236c00ec290816ab866ff3d67cf058ecf5c88f0034e331a1ab77cdef1df25111
7
+ data.tar.gz: 79de546a04f2ca9fe49246be7df31582cafc791799bbacd868af7fa1e381e42a462685e619a734745500203a25587a7eb6eaee04465b269cee8242ad67334a1b
@@ -230,6 +230,12 @@ module CLI
230
230
  end
231
231
  elsif n == 0
232
232
  # Ignore pressing "0" when not in multiple mode
233
+ elsif should_enter_select_mode?(n)
234
+ # When we have more than 9 options, we need to enter select mode
235
+ # to avoid pre-selecting (e.g) 1 when the user wanted 10.
236
+ # This also applies to 2 and 20+ options, 3/30+, etc.
237
+ start_line_select
238
+ @active = n
233
239
  else
234
240
  @active = n
235
241
  @answer = n
@@ -237,6 +243,20 @@ module CLI
237
243
  @redraw = true
238
244
  end
239
245
 
246
+ sig { params(n: Integer).returns(T::Boolean) }
247
+ def should_enter_select_mode?(n)
248
+ # If we have less than 10 options, we don't need to enter select mode
249
+ # and we can just select the option directly. This just keeps the code easier
250
+ # by making the cases simpler to understand
251
+ return false if @options.length <= 9
252
+
253
+ # At this point we have 10+ options so always need to check if we should run.
254
+ # This can be simplified to checking if the length of options is >= to the option selected * 10:
255
+ # n == 1 && options.length >= 10 (1 * 10), n == 2 && options.length >= 20 (2 * 10), etc.
256
+ # which can be further simplified to just:
257
+ @options.length >= (n * 10)
258
+ end
259
+
240
260
  sig { params(char: String).void }
241
261
  def select_bool(char)
242
262
  return unless (@options - ['yes', 'no']).empty?
@@ -3,6 +3,6 @@
3
3
 
4
4
  module CLI
5
5
  module UI
6
- VERSION = '2.3.0'
6
+ VERSION = '2.3.1'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,16 +1,16 @@
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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  - Julian Nadeau
9
9
  - Lisa Ugray
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-12-10 00:00:00.000000000 Z
13
+ date: 2025-03-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -86,7 +86,7 @@ homepage: https://github.com/shopify/cli-ui
86
86
  licenses:
87
87
  - MIT
88
88
  metadata: {}
89
- post_install_message:
89
+ post_install_message:
90
90
  rdoc_options: []
91
91
  require_paths:
92
92
  - lib
@@ -101,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 3.0.3.1
105
- signing_key:
104
+ rubygems_version: 3.5.9
105
+ signing_key:
106
106
  specification_version: 4
107
107
  summary: Terminal UI framework
108
108
  test_files: []