cli-ui 2.4.0 → 2.6.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/ansi.rb +23 -27
- data/lib/cli/ui/color.rb +7 -13
- data/lib/cli/ui/formatter.rb +23 -23
- data/lib/cli/ui/frame/frame_stack.rb +9 -21
- data/lib/cli/ui/frame/frame_style/box.rb +11 -10
- data/lib/cli/ui/frame/frame_style/bracket.rb +11 -10
- data/lib/cli/ui/frame/frame_style.rb +31 -22
- data/lib/cli/ui/frame.rb +12 -43
- data/lib/cli/ui/glyph.rb +8 -14
- data/lib/cli/ui/os.rb +6 -10
- data/lib/cli/ui/printer.rb +1 -15
- data/lib/cli/ui/progress.rb +20 -23
- data/lib/cli/ui/progress_reporter.rb +209 -0
- data/lib/cli/ui/prompt/interactive_options.rb +46 -54
- data/lib/cli/ui/prompt/options_handler.rb +4 -6
- data/lib/cli/ui/prompt.rb +22 -45
- data/lib/cli/ui/spinner/async.rb +3 -7
- data/lib/cli/ui/spinner/spin_group.rb +205 -135
- data/lib/cli/ui/spinner.rb +3 -16
- data/lib/cli/ui/stdout_router.rb +38 -55
- data/lib/cli/ui/table.rb +3 -7
- data/lib/cli/ui/terminal.rb +4 -8
- data/lib/cli/ui/truncater.rb +5 -6
- data/lib/cli/ui/version.rb +1 -1
- data/lib/cli/ui/widgets/base.rb +13 -14
- data/lib/cli/ui/widgets/status.rb +10 -10
- data/lib/cli/ui/widgets.rb +7 -15
- data/lib/cli/ui/work_queue.rb +23 -27
- data/lib/cli/ui/wrap.rb +3 -5
- data/lib/cli/ui.rb +42 -97
- metadata +3 -3
- data/lib/cli/ui/sorbet_runtime_stub.rb +0 -168
data/lib/cli/ui/prompt.rb
CHANGED
@@ -17,9 +17,7 @@ module CLI
|
|
17
17
|
autoload :OptionsHandler, 'cli/ui/prompt/options_handler'
|
18
18
|
|
19
19
|
class << self
|
20
|
-
|
21
|
-
|
22
|
-
sig { returns(Color) }
|
20
|
+
#: -> Color
|
23
21
|
def instructions_color
|
24
22
|
@instructions_color ||= Color::YELLOW
|
25
23
|
end
|
@@ -30,7 +28,7 @@ module CLI
|
|
30
28
|
#
|
31
29
|
# * +color+ - the color to use for prompt instructions
|
32
30
|
#
|
33
|
-
|
31
|
+
#: (colorable color) -> void
|
34
32
|
def instructions_color=(color)
|
35
33
|
@instructions_color = CLI::UI.resolve_color(color)
|
36
34
|
end
|
@@ -102,19 +100,7 @@ module CLI
|
|
102
100
|
# handler.option('python') { |selection| selection }
|
103
101
|
# end
|
104
102
|
#
|
105
|
-
|
106
|
-
params(
|
107
|
-
question: String,
|
108
|
-
options: T.nilable(T::Array[String]),
|
109
|
-
default: T.nilable(T.any(String, T::Array[String])),
|
110
|
-
is_file: T::Boolean,
|
111
|
-
allow_empty: T::Boolean,
|
112
|
-
multiple: T::Boolean,
|
113
|
-
filter_ui: T::Boolean,
|
114
|
-
select_ui: T::Boolean,
|
115
|
-
options_proc: T.nilable(T.proc.params(handler: OptionsHandler).void),
|
116
|
-
).returns(T.any(String, T::Array[String]))
|
117
|
-
end
|
103
|
+
#: (String question, ?options: Array[String]?, ?default: (String | Array[String])?, ?is_file: bool, ?allow_empty: bool, ?multiple: bool, ?filter_ui: bool, ?select_ui: bool) ?{ (OptionsHandler handler) -> void } -> (String | Array[String])
|
118
104
|
def ask(
|
119
105
|
question,
|
120
106
|
options: nil,
|
@@ -154,7 +140,12 @@ module CLI
|
|
154
140
|
&options_proc
|
155
141
|
)
|
156
142
|
else
|
157
|
-
ask_free_form(
|
143
|
+
ask_free_form(
|
144
|
+
question,
|
145
|
+
default, #: as String?
|
146
|
+
is_file,
|
147
|
+
allow_empty,
|
148
|
+
)
|
158
149
|
end
|
159
150
|
end
|
160
151
|
|
@@ -165,7 +156,7 @@ module CLI
|
|
165
156
|
#
|
166
157
|
# The password, without a trailing newline.
|
167
158
|
# If the user simply presses "Enter" without typing any password, this will return an empty string.
|
168
|
-
|
159
|
+
#: (String question) -> String
|
169
160
|
def ask_password(question)
|
170
161
|
require 'io/console'
|
171
162
|
|
@@ -196,7 +187,7 @@ module CLI
|
|
196
187
|
#
|
197
188
|
# CLI::UI::Prompt.confirm('Do a dangerous thing?', default: false)
|
198
189
|
#
|
199
|
-
|
190
|
+
#: (String question, ?default: bool) -> bool
|
200
191
|
def confirm(question, default: true)
|
201
192
|
ask_interactive(question, default ? ['yes', 'no'] : ['no', 'yes'], filter_ui: false) == 'yes'
|
202
193
|
end
|
@@ -208,7 +199,7 @@ module CLI
|
|
208
199
|
# CLI::UI::Prompt.any_key # Press any key to continue...
|
209
200
|
#
|
210
201
|
# CLI::UI::Prompt.any_key('Press RETURN to continue...') # Then check if that's what they pressed
|
211
|
-
|
202
|
+
#: (?String prompt) -> String?
|
212
203
|
def any_key(prompt = 'Press any key to continue...')
|
213
204
|
CLI::UI::StdoutRouter::Capture.in_alternate_screen do
|
214
205
|
puts_question(prompt)
|
@@ -217,7 +208,7 @@ module CLI
|
|
217
208
|
end
|
218
209
|
|
219
210
|
# Wait for any key to be pressed, returning the pressed key.
|
220
|
-
|
211
|
+
#: -> String?
|
221
212
|
def read_char
|
222
213
|
CLI::UI::StdoutRouter::Capture.in_alternate_screen do
|
223
214
|
if $stdin.tty? && !ENV['TEST']
|
@@ -233,10 +224,7 @@ module CLI
|
|
233
224
|
|
234
225
|
private
|
235
226
|
|
236
|
-
|
237
|
-
params(question: String, default: T.nilable(String), is_file: T::Boolean, allow_empty: T::Boolean)
|
238
|
-
.returns(String)
|
239
|
-
end
|
227
|
+
#: (String question, String? default, bool is_file, bool allow_empty) -> String
|
240
228
|
def ask_free_form(question, default, is_file, allow_empty)
|
241
229
|
if default && !allow_empty
|
242
230
|
raise(ArgumentError, 'conflicting arguments: default enabled but allow_empty is false')
|
@@ -265,16 +253,7 @@ module CLI
|
|
265
253
|
end
|
266
254
|
end
|
267
255
|
|
268
|
-
|
269
|
-
params(
|
270
|
-
question: String,
|
271
|
-
options: T.nilable(T::Array[String]),
|
272
|
-
multiple: T::Boolean,
|
273
|
-
default: T.nilable(T.any(String, T::Array[String])),
|
274
|
-
filter_ui: T::Boolean,
|
275
|
-
select_ui: T::Boolean,
|
276
|
-
).returns(T.any(String, T::Array[String]))
|
277
|
-
end
|
256
|
+
#: (String question, ?Array[String]? options, ?multiple: bool, ?default: (String | Array[String])?, ?filter_ui: bool, ?select_ui: bool) -> (String | Array[String])
|
278
257
|
def ask_interactive(question, options = nil, multiple: false, default: nil, filter_ui: true, select_ui: true)
|
279
258
|
raise(ArgumentError, 'conflicting arguments: options and block given') if options && block_given?
|
280
259
|
|
@@ -296,7 +275,7 @@ module CLI
|
|
296
275
|
instructions += ", filter with 'f'" if filter_ui
|
297
276
|
instructions += ", enter option with 'e'" if select_ui && (options.size > 9)
|
298
277
|
|
299
|
-
resp =
|
278
|
+
resp = [] #: (String | Array[String])
|
300
279
|
|
301
280
|
CLI::UI::StdoutRouter::Capture.in_alternate_screen do
|
302
281
|
puts_question("#{question} " + instructions_color.code + "(#{instructions})" + Color::RESET.code)
|
@@ -325,24 +304,22 @@ module CLI
|
|
325
304
|
end
|
326
305
|
|
327
306
|
if block_given?
|
328
|
-
|
307
|
+
h = handler #: as !nil
|
308
|
+
h.call(resp)
|
329
309
|
else
|
330
310
|
resp
|
331
311
|
end
|
332
312
|
end
|
333
313
|
|
334
314
|
# Useful for stubbing in tests
|
335
|
-
|
336
|
-
params(options: T::Array[String], multiple: T::Boolean, default: T.nilable(T.any(T::Array[String], String)))
|
337
|
-
.returns(T.any(T::Array[String], String))
|
338
|
-
end
|
315
|
+
#: (Array[String] options, ?multiple: bool, ?default: (Array[String] | String)?) -> (Array[String] | String)
|
339
316
|
def interactive_prompt(options, multiple: false, default: nil)
|
340
317
|
CLI::UI::StdoutRouter::Capture.in_alternate_screen do
|
341
318
|
InteractiveOptions.call(options, multiple: multiple, default: default)
|
342
319
|
end
|
343
320
|
end
|
344
321
|
|
345
|
-
|
322
|
+
#: (String default) -> void
|
346
323
|
def write_default_over_empty_input(default)
|
347
324
|
CLI::UI.raw do
|
348
325
|
$stderr.puts(
|
@@ -355,12 +332,12 @@ module CLI
|
|
355
332
|
end
|
356
333
|
end
|
357
334
|
|
358
|
-
|
335
|
+
#: (String str) -> void
|
359
336
|
def puts_question(str)
|
360
337
|
$stdout.puts(CLI::UI.fmt('{{?}} ' + str))
|
361
338
|
end
|
362
339
|
|
363
|
-
|
340
|
+
#: (?is_file: bool) -> String
|
364
341
|
def readline(is_file: false)
|
365
342
|
if is_file
|
366
343
|
Reline.completion_proc = proc do |input|
|
data/lib/cli/ui/spinner/async.rb
CHANGED
@@ -5,14 +5,10 @@ module CLI
|
|
5
5
|
module UI
|
6
6
|
module Spinner
|
7
7
|
class Async
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
class << self
|
11
|
-
extend T::Sig
|
12
|
-
|
13
9
|
# Convenience method for +initialize+
|
14
10
|
#
|
15
|
-
|
11
|
+
#: (String title) -> Async
|
16
12
|
def start(title)
|
17
13
|
new(title)
|
18
14
|
end
|
@@ -29,7 +25,7 @@ module CLI
|
|
29
25
|
#
|
30
26
|
# CLI::UI::Spinner::Async.new('Title')
|
31
27
|
#
|
32
|
-
|
28
|
+
#: (String title) -> void
|
33
29
|
def initialize(title)
|
34
30
|
require 'thread'
|
35
31
|
sg = CLI::UI::Spinner::SpinGroup.new
|
@@ -41,7 +37,7 @@ module CLI
|
|
41
37
|
|
42
38
|
# Stops an asynchronous spinner
|
43
39
|
#
|
44
|
-
|
40
|
+
#: -> bool
|
45
41
|
def stop
|
46
42
|
@m.synchronize { @cv.signal }
|
47
43
|
@t.value
|