cli-ui 1.5.1 → 2.2.3
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/README.md +28 -17
- data/lib/cli/ui/ansi.rb +172 -129
- data/lib/cli/ui/color.rb +39 -20
- data/lib/cli/ui/formatter.rb +46 -21
- data/lib/cli/ui/frame/frame_stack.rb +30 -50
- data/lib/cli/ui/frame/frame_style/box.rb +16 -5
- data/lib/cli/ui/frame/frame_style/bracket.rb +19 -8
- data/lib/cli/ui/frame/frame_style.rb +84 -87
- data/lib/cli/ui/frame.rb +79 -32
- data/lib/cli/ui/glyph.rb +44 -31
- data/lib/cli/ui/os.rb +44 -48
- data/lib/cli/ui/printer.rb +65 -47
- data/lib/cli/ui/progress.rb +50 -33
- data/lib/cli/ui/prompt/interactive_options.rb +114 -68
- data/lib/cli/ui/prompt/options_handler.rb +8 -0
- data/lib/cli/ui/prompt.rb +168 -58
- data/lib/cli/ui/sorbet_runtime_stub.rb +169 -0
- data/lib/cli/ui/spinner/async.rb +15 -4
- data/lib/cli/ui/spinner/spin_group.rb +174 -36
- data/lib/cli/ui/spinner.rb +48 -28
- data/lib/cli/ui/stdout_router.rb +229 -47
- data/lib/cli/ui/terminal.rb +37 -25
- data/lib/cli/ui/truncater.rb +7 -2
- data/lib/cli/ui/version.rb +3 -1
- data/lib/cli/ui/widgets/base.rb +23 -4
- data/lib/cli/ui/widgets/status.rb +19 -1
- data/lib/cli/ui/widgets.rb +42 -23
- data/lib/cli/ui/wrap.rb +8 -1
- data/lib/cli/ui.rb +336 -188
- data/vendor/reentrant_mutex.rb +78 -0
- metadata +11 -9
data/lib/cli/ui/widgets.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
require('cli/ui')
|
2
4
|
|
3
5
|
module CLI
|
@@ -16,57 +18,74 @@ module CLI
|
|
16
18
|
# CLI::UI::Widgets.register('my-widget') { MyWidget }
|
17
19
|
# puts(CLI::UI.fmt("{{@widget/my-widget:args}}"))
|
18
20
|
module Widgets
|
21
|
+
extend T::Sig
|
22
|
+
|
19
23
|
MAP = {}
|
20
24
|
|
21
25
|
autoload(:Base, 'cli/ui/widgets/base')
|
26
|
+
autoload(:Status, 'cli/ui/widgets/status')
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
28
|
+
class << self
|
29
|
+
extend T::Sig
|
26
30
|
|
27
|
-
|
28
|
-
|
31
|
+
sig { params(name: String, cb: T.proc.returns(T.class_of(Widgets::Base))).void }
|
32
|
+
def register(name, &cb)
|
33
|
+
MAP[name] = cb
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# Looks up a widget by handle
|
37
|
+
#
|
38
|
+
# ==== Raises
|
39
|
+
# Raises InvalidWidgetHandle if the widget is not available.
|
40
|
+
#
|
41
|
+
# ==== Returns
|
42
|
+
# A callable widget, to be invoked like `.call(argstring)`
|
43
|
+
#
|
44
|
+
sig { params(handle: String).returns(T.class_of(Widgets::Base)) }
|
45
|
+
def lookup(handle)
|
46
|
+
MAP.fetch(handle).call
|
47
|
+
rescue KeyError, NameError
|
48
|
+
raise(InvalidWidgetHandle, handle)
|
49
|
+
end
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
# All available widgets by name
|
52
|
+
#
|
53
|
+
sig { returns(T::Array[String]) }
|
54
|
+
def available
|
55
|
+
MAP.keys
|
56
|
+
end
|
48
57
|
end
|
49
58
|
|
59
|
+
register('status') { Widgets::Status }
|
60
|
+
|
50
61
|
class InvalidWidgetHandle < ArgumentError
|
62
|
+
extend T::Sig
|
63
|
+
|
64
|
+
sig { params(handle: String).void }
|
51
65
|
def initialize(handle)
|
52
66
|
super
|
53
67
|
@handle = handle
|
54
68
|
end
|
55
69
|
|
70
|
+
sig { returns(String) }
|
56
71
|
def message
|
57
|
-
keys =
|
72
|
+
keys = Widgets.available.join(',')
|
58
73
|
"invalid widget handle: #{@handle} " \
|
59
74
|
"-- must be one of CLI::UI::Widgets.available (#{keys})"
|
60
75
|
end
|
61
76
|
end
|
62
77
|
|
63
78
|
class InvalidWidgetArguments < ArgumentError
|
79
|
+
extend T::Sig
|
80
|
+
|
81
|
+
sig { params(argstring: String, pattern: Regexp).void }
|
64
82
|
def initialize(argstring, pattern)
|
65
83
|
super
|
66
84
|
@argstring = argstring
|
67
85
|
@pattern = pattern
|
68
86
|
end
|
69
87
|
|
88
|
+
sig { returns(String) }
|
70
89
|
def message
|
71
90
|
"invalid widget arguments: #{@argstring} " \
|
72
91
|
"-- must match pattern: #{@pattern.inspect}"
|
data/lib/cli/ui/wrap.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
|
2
5
|
require 'cli/ui'
|
3
6
|
require 'cli/ui/frame/frame_stack'
|
4
7
|
require 'cli/ui/frame/frame_style'
|
@@ -6,13 +9,17 @@ require 'cli/ui/frame/frame_style'
|
|
6
9
|
module CLI
|
7
10
|
module UI
|
8
11
|
class Wrap
|
12
|
+
extend T::Sig
|
13
|
+
|
14
|
+
sig { params(input: String).void }
|
9
15
|
def initialize(input)
|
10
16
|
@input = input
|
11
17
|
end
|
12
18
|
|
19
|
+
sig { returns(String) }
|
13
20
|
def wrap
|
14
21
|
max_width = Terminal.width - Frame.prefix_width
|
15
|
-
width = 0
|
22
|
+
width = T.let(0, Integer)
|
16
23
|
final = []
|
17
24
|
# Create an alternation of format codes of parameter lengths 1-20, since + and {1,n} not allowed in lookbehind
|
18
25
|
format_codes = (1..20).map { |n| /\x1b\[[\d;]{#{n}}m/ }.join('|')
|