fluid_cli 0.1.9 → 0.2.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 +4 -4
- data/README.md +200 -1
- data/exe/fluid +12 -17
- data/lib/fluid_cli/version.rb +1 -1
- data/lib/fluid_cli.rb +4 -62
- metadata +14 -278
- data/Rakefile +0 -26
- data/dev.yml +0 -5
- data/lib/fluid_cli/api.rb +0 -141
- data/lib/fluid_cli/assets/post_auth_page/index.html.erb +0 -34
- data/lib/fluid_cli/assets/post_auth_page/style.css +0 -58
- data/lib/fluid_cli/command.rb +0 -55
- data/lib/fluid_cli/commands/help.rb +0 -21
- data/lib/fluid_cli/commands/login.rb +0 -30
- data/lib/fluid_cli/commands/logout.rb +0 -38
- data/lib/fluid_cli/commands/switch.rb +0 -23
- data/lib/fluid_cli/commands/theme/common/company_helper.rb +0 -15
- data/lib/fluid_cli/commands/theme/common/root_helper.rb +0 -95
- data/lib/fluid_cli/commands/theme/dev.rb +0 -62
- data/lib/fluid_cli/commands/theme/help.rb +0 -21
- data/lib/fluid_cli/commands/theme/init.rb +0 -46
- data/lib/fluid_cli/commands/theme/navigate.rb +0 -57
- data/lib/fluid_cli/commands/theme/pull.rb +0 -68
- data/lib/fluid_cli/commands/theme/push.rb +0 -132
- data/lib/fluid_cli/commands/theme.rb +0 -24
- data/lib/fluid_cli/commands/whoami.rb +0 -23
- data/lib/fluid_cli/commands.rb +0 -19
- data/lib/fluid_cli/company_switcher.rb +0 -69
- data/lib/fluid_cli/context.rb +0 -691
- data/lib/fluid_cli/db.rb +0 -114
- data/lib/fluid_cli/entry_point.rb +0 -10
- data/lib/fluid_cli/environment.rb +0 -32
- data/lib/fluid_cli/file_system_listener.rb +0 -29
- data/lib/fluid_cli/form.rb +0 -42
- data/lib/fluid_cli/git.rb +0 -319
- data/lib/fluid_cli/http_request.rb +0 -60
- data/lib/fluid_cli/identity_auth/servlet.rb +0 -39
- data/lib/fluid_cli/identity_auth.rb +0 -126
- data/lib/fluid_cli/options.rb +0 -38
- data/lib/fluid_cli/packager.rb +0 -36
- data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +0 -79
- data/lib/fluid_cli/theme/dev_server/errors.rb +0 -9
- data/lib/fluid_cli/theme/dev_server/header_hash.rb +0 -98
- data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +0 -39
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +0 -27
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +0 -28
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +0 -43
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +0 -16
- data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +0 -54
- data/lib/fluid_cli/theme/dev_server/hot_reload.rb +0 -75
- data/lib/fluid_cli/theme/dev_server/local_assets.rb +0 -92
- data/lib/fluid_cli/theme/dev_server/proxy.rb +0 -235
- data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +0 -82
- data/lib/fluid_cli/theme/dev_server/reload_mode.rb +0 -34
- data/lib/fluid_cli/theme/dev_server/sse.rb +0 -75
- data/lib/fluid_cli/theme/dev_server/watcher.rb +0 -57
- data/lib/fluid_cli/theme/dev_server/web_server.rb +0 -140
- data/lib/fluid_cli/theme/dev_server.rb +0 -308
- data/lib/fluid_cli/theme/development_theme.rb +0 -101
- data/lib/fluid_cli/theme/file.rb +0 -130
- data/lib/fluid_cli/theme/forms/select.rb +0 -33
- data/lib/fluid_cli/theme/mime_type.rb +0 -34
- data/lib/fluid_cli/theme/navigation/resource_fetcher.rb +0 -25
- data/lib/fluid_cli/theme/navigation/route_navigator.rb +0 -87
- data/lib/fluid_cli/theme/presenters/theme_presenter.rb +0 -49
- data/lib/fluid_cli/theme/presenters/themes_presenter.rb +0 -31
- data/lib/fluid_cli/theme/root.rb +0 -62
- data/lib/fluid_cli/theme/schema_validator.rb +0 -274
- data/lib/fluid_cli/theme/syncer/checksums.rb +0 -66
- data/lib/fluid_cli/theme/syncer/downloader.rb +0 -54
- data/lib/fluid_cli/theme/syncer/error_reporter.rb +0 -45
- data/lib/fluid_cli/theme/syncer/merger.rb +0 -53
- data/lib/fluid_cli/theme/syncer/operation.rb +0 -58
- data/lib/fluid_cli/theme/syncer/standard_reporter.rb +0 -32
- data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +0 -90
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +0 -41
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +0 -37
- data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +0 -64
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +0 -29
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +0 -30
- data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +0 -49
- data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +0 -71
- data/lib/fluid_cli/theme/syncer/uploader.rb +0 -105
- data/lib/fluid_cli/theme/syncer.rb +0 -500
- data/lib/fluid_cli/theme/theme.rb +0 -186
- data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +0 -22
- data/lib/fluid_cli/thread_pool/job.rb +0 -35
- data/lib/fluid_cli/thread_pool.rb +0 -49
- data/packaging/homebrew/fluid_cli.base.rb +0 -103
- data/vendor/deps/base64/.document +0 -5
- data/vendor/deps/base64/.gitignore +0 -9
- data/vendor/deps/base64/BSDL +0 -22
- data/vendor/deps/base64/COPYING +0 -56
- data/vendor/deps/base64/Gemfile +0 -9
- data/vendor/deps/base64/LEGAL +0 -60
- data/vendor/deps/base64/README.md +0 -48
- data/vendor/deps/base64/Rakefile +0 -31
- data/vendor/deps/base64/base64.gemspec +0 -28
- data/vendor/deps/base64/bin/console +0 -14
- data/vendor/deps/base64/bin/setup +0 -8
- data/vendor/deps/base64/lib/base64.rb +0 -382
- data/vendor/deps/base64/sig/base64.rbs +0 -358
- data/vendor/deps/base64/test/base64/test_base64.rb +0 -115
- data/vendor/deps/base64/test_sig/test_base64.rb +0 -44
- data/vendor/deps/cli-kit/REVISION +0 -1
- data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +0 -286
- data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +0 -215
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +0 -128
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +0 -125
- data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +0 -130
- data/vendor/deps/cli-kit/lib/cli/kit/args.rb +0 -16
- data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +0 -30
- data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +0 -268
- data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +0 -150
- data/vendor/deps/cli-kit/lib/cli/kit/config.rb +0 -137
- data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +0 -28
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +0 -166
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +0 -92
- data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +0 -91
- data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +0 -92
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +0 -94
- data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +0 -248
- data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +0 -55
- data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +0 -66
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +0 -260
- data/vendor/deps/cli-kit/lib/cli/kit/support.rb +0 -11
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +0 -290
- data/vendor/deps/cli-kit/lib/cli/kit/util.rb +0 -118
- data/vendor/deps/cli-kit/lib/cli/kit/version.rb +0 -7
- data/vendor/deps/cli-kit/lib/cli/kit.rb +0 -139
- data/vendor/deps/cli-ui/REVISION +0 -1
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +0 -218
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +0 -101
- data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +0 -219
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +0 -67
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +0 -179
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +0 -152
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +0 -127
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +0 -286
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +0 -92
- data/vendor/deps/cli-ui/lib/cli/ui/os.rb +0 -63
- data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +0 -64
- data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +0 -132
- data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +0 -209
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +0 -583
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +0 -36
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +0 -381
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +0 -48
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +0 -602
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +0 -79
- data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +0 -399
- data/vendor/deps/cli-ui/lib/cli/ui/table.rb +0 -83
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +0 -55
- data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +0 -106
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +0 -8
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +0 -46
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +0 -79
- data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +0 -89
- data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +0 -142
- data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +0 -61
- data/vendor/deps/cli-ui/lib/cli/ui.rb +0 -359
- data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +0 -78
- data/vendor/deps/webrick/.gitignore +0 -9
- data/vendor/deps/webrick/Gemfile +0 -3
- data/vendor/deps/webrick/LICENSE.txt +0 -22
- data/vendor/deps/webrick/README.md +0 -61
- data/vendor/deps/webrick/Rakefile +0 -10
- data/vendor/deps/webrick/lib/webrick/accesslog.rb +0 -157
- data/vendor/deps/webrick/lib/webrick/cgi.rb +0 -313
- data/vendor/deps/webrick/lib/webrick/compat.rb +0 -36
- data/vendor/deps/webrick/lib/webrick/config.rb +0 -158
- data/vendor/deps/webrick/lib/webrick/cookie.rb +0 -172
- data/vendor/deps/webrick/lib/webrick/htmlutils.rb +0 -30
- data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +0 -117
- data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +0 -116
- data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +0 -395
- data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +0 -132
- data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +0 -97
- data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +0 -158
- data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +0 -53
- data/vendor/deps/webrick/lib/webrick/httpauth.rb +0 -96
- data/vendor/deps/webrick/lib/webrick/httpproxy.rb +0 -354
- data/vendor/deps/webrick/lib/webrick/httprequest.rb +0 -636
- data/vendor/deps/webrick/lib/webrick/httpresponse.rb +0 -564
- data/vendor/deps/webrick/lib/webrick/https.rb +0 -152
- data/vendor/deps/webrick/lib/webrick/httpserver.rb +0 -294
- data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +0 -152
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +0 -47
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +0 -126
- data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +0 -88
- data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +0 -552
- data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +0 -47
- data/vendor/deps/webrick/lib/webrick/httpservlet.rb +0 -23
- data/vendor/deps/webrick/lib/webrick/httpstatus.rb +0 -194
- data/vendor/deps/webrick/lib/webrick/httputils.rb +0 -512
- data/vendor/deps/webrick/lib/webrick/httpversion.rb +0 -76
- data/vendor/deps/webrick/lib/webrick/log.rb +0 -156
- data/vendor/deps/webrick/lib/webrick/server.rb +0 -381
- data/vendor/deps/webrick/lib/webrick/ssl.rb +0 -215
- data/vendor/deps/webrick/lib/webrick/utils.rb +0 -265
- data/vendor/deps/webrick/lib/webrick/version.rb +0 -18
- data/vendor/deps/webrick/lib/webrick.rb +0 -232
- data/vendor/deps/webrick/webrick.gemspec +0 -74
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'cli/ui'
|
|
5
|
-
require 'stringio'
|
|
6
|
-
require_relative '../../../vendor/reentrant_mutex'
|
|
7
|
-
|
|
8
|
-
module CLI
|
|
9
|
-
module UI
|
|
10
|
-
module StdoutRouter
|
|
11
|
-
class Writer
|
|
12
|
-
#: (io_like stream, Symbol name) -> void
|
|
13
|
-
def initialize(stream, name)
|
|
14
|
-
@stream = stream
|
|
15
|
-
@name = name
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
#: (*Object args) -> Integer
|
|
19
|
-
def write(*args)
|
|
20
|
-
strs = args.map do |obj|
|
|
21
|
-
str = obj.to_s
|
|
22
|
-
if auto_frame_inset?
|
|
23
|
-
str = str.dup # unfreeze
|
|
24
|
-
str = str.to_s.force_encoding(Encoding::UTF_8)
|
|
25
|
-
apply_line_prefix(str, CLI::UI::Frame.prefix)
|
|
26
|
-
else
|
|
27
|
-
@pending_newline = false
|
|
28
|
-
str
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# hook return of false suppresses output.
|
|
33
|
-
if (hook = Thread.current[:cliui_output_hook])
|
|
34
|
-
return 0 if hook.call(strs.join, @name) == false
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
stream_args = prepend_id(@stream, strs) #: as untyped
|
|
38
|
-
ret = @stream.write_without_cli_ui(*stream_args) #: as Integer
|
|
39
|
-
if (dup = StdoutRouter.duplicate_output_to)
|
|
40
|
-
begin
|
|
41
|
-
dup_args = prepend_id(dup, strs) #: as untyped
|
|
42
|
-
dup.write(*dup_args) #: as Integer
|
|
43
|
-
rescue IOError
|
|
44
|
-
# Ignore
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
ret
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
#: (io_like stream, Array[String] args) -> Array[String]
|
|
53
|
-
def prepend_id(stream, args)
|
|
54
|
-
return args unless prepend_id_for_stream(stream)
|
|
55
|
-
|
|
56
|
-
args.map do |a|
|
|
57
|
-
next a if a.chomp.empty? # allow new lines to be new lines
|
|
58
|
-
|
|
59
|
-
"[#{Thread.current[:cliui_output_id][:id]}] #{a}"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
#: (io_like stream) -> bool
|
|
64
|
-
def prepend_id_for_stream(stream)
|
|
65
|
-
return false unless Thread.current[:cliui_output_id]
|
|
66
|
-
return true if Thread.current[:cliui_output_id][:streams].include?(stream)
|
|
67
|
-
|
|
68
|
-
false
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
#: -> bool
|
|
72
|
-
def auto_frame_inset?
|
|
73
|
-
!Thread.current[:no_cliui_frame_inset]
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
#: (String str, String prefix) -> String
|
|
77
|
-
def apply_line_prefix(str, prefix)
|
|
78
|
-
return '' if str.empty?
|
|
79
|
-
|
|
80
|
-
prefixed = +''
|
|
81
|
-
str.force_encoding(Encoding::UTF_8).lines.each do |line|
|
|
82
|
-
if @pending_newline
|
|
83
|
-
prefixed << line
|
|
84
|
-
@pending_newline = false
|
|
85
|
-
else
|
|
86
|
-
prefixed << prefix << line
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
@pending_newline = !str.end_with?("\n")
|
|
90
|
-
prefixed
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
class Capture
|
|
95
|
-
@capture_mutex = Mutex.new
|
|
96
|
-
@stdin_mutex = CLI::UI::ReentrantMutex.new
|
|
97
|
-
@active_captures = 0
|
|
98
|
-
@saved_stdin = nil
|
|
99
|
-
|
|
100
|
-
class << self
|
|
101
|
-
#: -> Capture?
|
|
102
|
-
def current_capture
|
|
103
|
-
Thread.current[:cliui_current_capture]
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
#: -> Capture
|
|
107
|
-
def current_capture!
|
|
108
|
-
current_capture #: as !nil
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
#: [T] { -> T } -> T
|
|
112
|
-
def in_alternate_screen(&block)
|
|
113
|
-
stdin_synchronize do
|
|
114
|
-
previous_print_captured_output = current_capture&.print_captured_output
|
|
115
|
-
current_capture&.print_captured_output = true
|
|
116
|
-
Spinner::SpinGroup.pause_spinners do
|
|
117
|
-
if outermost_uncaptured?
|
|
118
|
-
begin
|
|
119
|
-
prev_hook = Thread.current[:cliui_output_hook]
|
|
120
|
-
Thread.current[:cliui_output_hook] = nil
|
|
121
|
-
replay = current_capture!.stdout.gsub(ANSI.match_alternate_screen, '')
|
|
122
|
-
CLI::UI.raw do
|
|
123
|
-
print("#{ANSI.enter_alternate_screen}#{replay}")
|
|
124
|
-
end
|
|
125
|
-
ensure
|
|
126
|
-
Thread.current[:cliui_output_hook] = prev_hook
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
block.call
|
|
130
|
-
ensure
|
|
131
|
-
print(ANSI.exit_alternate_screen) if outermost_uncaptured?
|
|
132
|
-
end
|
|
133
|
-
ensure
|
|
134
|
-
current_capture&.print_captured_output = !!previous_print_captured_output
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
#: [T] { -> T } -> T
|
|
139
|
-
def stdin_synchronize(&block)
|
|
140
|
-
@stdin_mutex.synchronize do
|
|
141
|
-
case $stdin
|
|
142
|
-
when BlockingInput
|
|
143
|
-
$stdin.synchronize do
|
|
144
|
-
block.call
|
|
145
|
-
end
|
|
146
|
-
else
|
|
147
|
-
block.call
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
#: [T] { -> T } -> T
|
|
153
|
-
def with_stdin_masked(&block)
|
|
154
|
-
@capture_mutex.synchronize do
|
|
155
|
-
if @active_captures.zero?
|
|
156
|
-
@stdin_mutex.synchronize do
|
|
157
|
-
@saved_stdin = $stdin
|
|
158
|
-
$stdin = BlockingInput.new(@saved_stdin)
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
@active_captures += 1
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
yield
|
|
165
|
-
ensure
|
|
166
|
-
@capture_mutex.synchronize do
|
|
167
|
-
@active_captures -= 1
|
|
168
|
-
if @active_captures.zero?
|
|
169
|
-
@stdin_mutex.synchronize do
|
|
170
|
-
$stdin = @saved_stdin
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
private
|
|
177
|
-
|
|
178
|
-
#: -> bool
|
|
179
|
-
def outermost_uncaptured?
|
|
180
|
-
@stdin_mutex.count == 1 && $stdin.is_a?(BlockingInput)
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
#: (?with_frame_inset: bool, ?merged_output: bool, ?duplicate_output_to: IO) { -> void } -> void
|
|
185
|
-
def initialize(
|
|
186
|
-
with_frame_inset: true,
|
|
187
|
-
merged_output: false,
|
|
188
|
-
duplicate_output_to: File.open(File::NULL, 'w'),
|
|
189
|
-
&block
|
|
190
|
-
)
|
|
191
|
-
@with_frame_inset = with_frame_inset
|
|
192
|
-
@merged_output = merged_output
|
|
193
|
-
@duplicate_output_to = duplicate_output_to
|
|
194
|
-
@block = block
|
|
195
|
-
@print_captured_output = false
|
|
196
|
-
@out = StringIO.new
|
|
197
|
-
@err = StringIO.new
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
#: bool
|
|
201
|
-
attr_accessor :print_captured_output
|
|
202
|
-
|
|
203
|
-
#: -> untyped
|
|
204
|
-
def run
|
|
205
|
-
require 'stringio'
|
|
206
|
-
|
|
207
|
-
StdoutRouter.assert_enabled!
|
|
208
|
-
|
|
209
|
-
Thread.current[:cliui_current_capture] = self
|
|
210
|
-
|
|
211
|
-
prev_frame_inset = Thread.current[:no_cliui_frame_inset]
|
|
212
|
-
prev_hook = Thread.current[:cliui_output_hook]
|
|
213
|
-
|
|
214
|
-
if Thread.current.respond_to?(:report_on_exception)
|
|
215
|
-
Thread.current.report_on_exception = false
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
self.class.with_stdin_masked do
|
|
219
|
-
Thread.current[:no_cliui_frame_inset] = !@with_frame_inset
|
|
220
|
-
Thread.current[:cliui_output_hook] = ->(data, stream) do
|
|
221
|
-
stream = :stdout if @merged_output
|
|
222
|
-
case stream
|
|
223
|
-
when :stdout
|
|
224
|
-
@out.write(data)
|
|
225
|
-
@duplicate_output_to.write(data)
|
|
226
|
-
when :stderr
|
|
227
|
-
@err.write(data)
|
|
228
|
-
else raise
|
|
229
|
-
end
|
|
230
|
-
print_captured_output # suppress writing to terminal by default
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
@block.call
|
|
234
|
-
end
|
|
235
|
-
ensure
|
|
236
|
-
Thread.current[:cliui_output_hook] = prev_hook
|
|
237
|
-
Thread.current[:no_cliui_frame_inset] = prev_frame_inset
|
|
238
|
-
Thread.current[:cliui_current_capture] = nil
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
#: -> String
|
|
242
|
-
def stdout
|
|
243
|
-
@out.string
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
#: -> String
|
|
247
|
-
def stderr
|
|
248
|
-
@err.string
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
class BlockingInput
|
|
252
|
-
#: (IO stream) -> void
|
|
253
|
-
def initialize(stream)
|
|
254
|
-
@stream = stream
|
|
255
|
-
@m = CLI::UI::ReentrantMutex.new
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
#: [T] { -> T } -> T
|
|
259
|
-
def synchronize(&block)
|
|
260
|
-
@m.synchronize do
|
|
261
|
-
previous_allowed_to_read = Thread.current[:cliui_allowed_to_read]
|
|
262
|
-
Thread.current[:cliui_allowed_to_read] = true
|
|
263
|
-
block.call
|
|
264
|
-
ensure
|
|
265
|
-
Thread.current[:cliui_allowed_to_read] = previous_allowed_to_read
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
READING_METHODS = [
|
|
270
|
-
:each,
|
|
271
|
-
:each_byte,
|
|
272
|
-
:each_char,
|
|
273
|
-
:each_codepoint,
|
|
274
|
-
:each_line,
|
|
275
|
-
:getbyte,
|
|
276
|
-
:getc,
|
|
277
|
-
:getch,
|
|
278
|
-
:gets,
|
|
279
|
-
:read,
|
|
280
|
-
:read_nonblock,
|
|
281
|
-
:readbyte,
|
|
282
|
-
:readchar,
|
|
283
|
-
:readline,
|
|
284
|
-
:readlines,
|
|
285
|
-
:readpartial,
|
|
286
|
-
]
|
|
287
|
-
|
|
288
|
-
NON_READING_METHODS = IO.instance_methods(false) - READING_METHODS
|
|
289
|
-
|
|
290
|
-
READING_METHODS.each do |method|
|
|
291
|
-
define_method(method) do |*args, **kwargs, &block|
|
|
292
|
-
raise(IOError, 'closed stream') unless Thread.current[:cliui_allowed_to_read]
|
|
293
|
-
|
|
294
|
-
@stream.send(method, *args, **kwargs, &block)
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
NON_READING_METHODS.each do |method|
|
|
299
|
-
define_method(method) do |*args, **kwargs, &block|
|
|
300
|
-
@stream.send(method, *args, **kwargs, &block)
|
|
301
|
-
end
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
class << self
|
|
307
|
-
WRITE_WITHOUT_CLI_UI = :write_without_cli_ui
|
|
308
|
-
|
|
309
|
-
NotEnabled = Class.new(StandardError)
|
|
310
|
-
|
|
311
|
-
#: io_like?
|
|
312
|
-
attr_accessor :duplicate_output_to
|
|
313
|
-
|
|
314
|
-
#: [T] (on_streams: Array[io_like]) { (String id) -> T } -> T
|
|
315
|
-
def with_id(on_streams:, &block)
|
|
316
|
-
require 'securerandom'
|
|
317
|
-
id = format('%05d', rand(10**5))
|
|
318
|
-
Thread.current[:cliui_output_id] = {
|
|
319
|
-
id: id,
|
|
320
|
-
streams: on_streams.map do |stream|
|
|
321
|
-
stream #: as io_like
|
|
322
|
-
end,
|
|
323
|
-
}
|
|
324
|
-
yield(id)
|
|
325
|
-
ensure
|
|
326
|
-
Thread.current[:cliui_output_id] = nil
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
#: -> Hash[Symbol, (String | io_like)]?
|
|
330
|
-
def current_id
|
|
331
|
-
Thread.current[:cliui_output_id]
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
#: -> void
|
|
335
|
-
def assert_enabled!
|
|
336
|
-
raise NotEnabled unless enabled?
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
#: [T] { -> T } -> T
|
|
340
|
-
def with_enabled(&block)
|
|
341
|
-
enable
|
|
342
|
-
yield
|
|
343
|
-
ensure
|
|
344
|
-
disable
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
# TODO: remove this
|
|
348
|
-
#: -> void
|
|
349
|
-
def ensure_activated
|
|
350
|
-
enable unless enabled?
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
#: -> bool
|
|
354
|
-
def enable
|
|
355
|
-
return false if enabled?($stdout) || enabled?($stderr)
|
|
356
|
-
|
|
357
|
-
activate($stdout, :stdout)
|
|
358
|
-
activate($stderr, :stderr)
|
|
359
|
-
true
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
#: (?io_like stream) -> bool
|
|
363
|
-
def enabled?(stream = $stdout)
|
|
364
|
-
stream.respond_to?(WRITE_WITHOUT_CLI_UI)
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
#: -> bool
|
|
368
|
-
def disable
|
|
369
|
-
return false unless enabled?($stdout) && enabled?($stderr)
|
|
370
|
-
|
|
371
|
-
deactivate($stdout)
|
|
372
|
-
deactivate($stderr)
|
|
373
|
-
true
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
private
|
|
377
|
-
|
|
378
|
-
#: (io_like stream) -> void
|
|
379
|
-
def deactivate(stream)
|
|
380
|
-
sc = stream.singleton_class
|
|
381
|
-
sc.send(:remove_method, :write)
|
|
382
|
-
sc.send(:alias_method, :write, WRITE_WITHOUT_CLI_UI)
|
|
383
|
-
end
|
|
384
|
-
|
|
385
|
-
#: (io_like stream, Symbol streamname) -> void
|
|
386
|
-
def activate(stream, streamname)
|
|
387
|
-
writer = StdoutRouter::Writer.new(stream, streamname)
|
|
388
|
-
|
|
389
|
-
raise if stream.respond_to?(WRITE_WITHOUT_CLI_UI)
|
|
390
|
-
|
|
391
|
-
stream.singleton_class.send(:alias_method, WRITE_WITHOUT_CLI_UI, :write)
|
|
392
|
-
stream.define_singleton_method(:write) do |*args|
|
|
393
|
-
writer.write(*args)
|
|
394
|
-
end
|
|
395
|
-
end
|
|
396
|
-
end
|
|
397
|
-
end
|
|
398
|
-
end
|
|
399
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
|
|
3
|
-
module CLI
|
|
4
|
-
module UI
|
|
5
|
-
module Table
|
|
6
|
-
class << self
|
|
7
|
-
# Prints a formatted table to the specified output
|
|
8
|
-
# Automatically pads columns to align based on the longest cell in each column,
|
|
9
|
-
# ignoring the width of ANSI color codes.
|
|
10
|
-
#
|
|
11
|
-
# ==== Attributes
|
|
12
|
-
#
|
|
13
|
-
# * +table+ - (required) 2D array of strings representing the table data
|
|
14
|
-
#
|
|
15
|
-
# ==== Options
|
|
16
|
-
#
|
|
17
|
-
# * +:col_spacing+ - Number of spaces between columns. Defaults to 1
|
|
18
|
-
# * +:to+ - Target stream, like $stdout or $stderr. Can be anything with print and puts methods,
|
|
19
|
-
# or under Sorbet, IO or StringIO. Defaults to $stdout
|
|
20
|
-
#
|
|
21
|
-
# ==== Example
|
|
22
|
-
#
|
|
23
|
-
# CLI::UI::Table.puts_table([
|
|
24
|
-
# ["{{bold:header_1}}", "{{bold:header_2}}"],
|
|
25
|
-
# ["really_long_cell", "short"],
|
|
26
|
-
# ["row2", "row2"]
|
|
27
|
-
# ])
|
|
28
|
-
#
|
|
29
|
-
# Default Output:
|
|
30
|
-
# header_1 header_2
|
|
31
|
-
# really_long_cell short
|
|
32
|
-
# row2 row2
|
|
33
|
-
#
|
|
34
|
-
#: (Array[Array[String]] table, ?col_spacing: Integer, ?to: io_like) -> void
|
|
35
|
-
def puts_table(table, col_spacing: 1, to: $stdout)
|
|
36
|
-
col_sizes = table.transpose.map do |col|
|
|
37
|
-
col.map { |cell| CLI::UI::ANSI.printing_width(CLI::UI.resolve_text(cell)) }.max
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
table.each do |row|
|
|
41
|
-
padded_row = row.each_with_index.map do |cell, i|
|
|
42
|
-
col_size = col_sizes[i] #: as !nil # guaranteed to be non-nil
|
|
43
|
-
cell_size = CLI::UI::ANSI.printing_width(CLI::UI.resolve_text(cell))
|
|
44
|
-
padded_cell = cell + ' ' * (col_size - cell_size)
|
|
45
|
-
padded_cell
|
|
46
|
-
end
|
|
47
|
-
CLI::UI.puts(padded_row.join(' ' * col_spacing), to: to)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Captures a table's output as an array of strings without printing to the terminal
|
|
52
|
-
# Can be used to further manipulate or format the table output
|
|
53
|
-
#
|
|
54
|
-
# ==== Attributes
|
|
55
|
-
#
|
|
56
|
-
# * +table+ - (required) 2D array of strings representing the table data
|
|
57
|
-
#
|
|
58
|
-
# ==== Options
|
|
59
|
-
#
|
|
60
|
-
# * +:col_spacing+ - Number of spaces between columns. Defaults to 1
|
|
61
|
-
#
|
|
62
|
-
# ==== Returns
|
|
63
|
-
#
|
|
64
|
-
# * +Array[String]+ - Array of strings, each representing a row of the formatted table
|
|
65
|
-
#
|
|
66
|
-
# ==== Example
|
|
67
|
-
#
|
|
68
|
-
# CLI::UI::Table.capture_table([
|
|
69
|
-
# ["{{bold:header_1}}", "{{bold:header_2}}"],
|
|
70
|
-
# ["really_long_cell", "short"],
|
|
71
|
-
# ["row2", "row2"]
|
|
72
|
-
# ])
|
|
73
|
-
#
|
|
74
|
-
#: (Array[Array[String]] table, ?col_spacing: Integer) -> Array[String]
|
|
75
|
-
def capture_table(table, col_spacing: 1)
|
|
76
|
-
strio = StringIO.new
|
|
77
|
-
puts_table(table, col_spacing: col_spacing, to: strio)
|
|
78
|
-
strio.string.lines.map(&:chomp)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'cli/ui'
|
|
5
|
-
require 'io/console'
|
|
6
|
-
|
|
7
|
-
module CLI
|
|
8
|
-
module UI
|
|
9
|
-
module Terminal
|
|
10
|
-
DEFAULT_WIDTH = 80
|
|
11
|
-
DEFAULT_HEIGHT = 24
|
|
12
|
-
|
|
13
|
-
class << self
|
|
14
|
-
# Returns the width of the terminal, if possible
|
|
15
|
-
# Otherwise will return DEFAULT_WIDTH
|
|
16
|
-
#
|
|
17
|
-
#: -> Integer
|
|
18
|
-
def width
|
|
19
|
-
winsize[1]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Returns the width of the terminal, if possible
|
|
23
|
-
# Otherwise, will return DEFAULT_HEIGHT
|
|
24
|
-
#
|
|
25
|
-
#: -> Integer
|
|
26
|
-
def height
|
|
27
|
-
winsize[0]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
#: -> [Integer, Integer]
|
|
31
|
-
def winsize
|
|
32
|
-
@winsize ||= begin
|
|
33
|
-
winsize = IO.console.winsize
|
|
34
|
-
setup_winsize_trap
|
|
35
|
-
|
|
36
|
-
if winsize.any?(&:zero?)
|
|
37
|
-
[DEFAULT_HEIGHT, DEFAULT_WIDTH]
|
|
38
|
-
else
|
|
39
|
-
winsize
|
|
40
|
-
end
|
|
41
|
-
rescue
|
|
42
|
-
[DEFAULT_HEIGHT, DEFAULT_WIDTH]
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
#: -> void
|
|
47
|
-
def setup_winsize_trap
|
|
48
|
-
@winsize_trap ||= Signal.trap('WINCH') do
|
|
49
|
-
@winsize = nil
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'cli/ui'
|
|
5
|
-
|
|
6
|
-
module CLI
|
|
7
|
-
module UI
|
|
8
|
-
# Truncater truncates a string to a provided printable width.
|
|
9
|
-
module Truncater
|
|
10
|
-
PARSE_ROOT = :root
|
|
11
|
-
PARSE_ANSI = :ansi
|
|
12
|
-
PARSE_ESC = :esc
|
|
13
|
-
PARSE_ZWJ = :zwj
|
|
14
|
-
|
|
15
|
-
ESC = 0x1b
|
|
16
|
-
LEFT_SQUARE_BRACKET = 0x5b
|
|
17
|
-
ZWJ = 0x200d # emojipedia.org/emoji-zwj-sequences
|
|
18
|
-
SEMICOLON = 0x3b
|
|
19
|
-
|
|
20
|
-
# EMOJI_RANGE in particular is super inaccurate. This is best-effort.
|
|
21
|
-
# If you need this to be more accurate, we'll almost certainly accept a
|
|
22
|
-
# PR improving it.
|
|
23
|
-
EMOJI_RANGE = 0x1f300..0x1f5ff
|
|
24
|
-
NUMERIC_RANGE = 0x30..0x39
|
|
25
|
-
LC_ALPHA_RANGE = 0x40..0x5a
|
|
26
|
-
UC_ALPHA_RANGE = 0x60..0x71
|
|
27
|
-
|
|
28
|
-
TRUNCATED = "\x1b[0m…"
|
|
29
|
-
|
|
30
|
-
class << self
|
|
31
|
-
#: (String text, Integer printing_width) -> String
|
|
32
|
-
def call(text, printing_width)
|
|
33
|
-
return text if text.size <= printing_width
|
|
34
|
-
|
|
35
|
-
width = 0
|
|
36
|
-
mode = PARSE_ROOT
|
|
37
|
-
truncation_index = nil #: Integer?
|
|
38
|
-
|
|
39
|
-
codepoints = text.codepoints
|
|
40
|
-
codepoints.each.with_index do |cp, index|
|
|
41
|
-
case mode
|
|
42
|
-
when PARSE_ROOT
|
|
43
|
-
case cp
|
|
44
|
-
when ESC # non-printable, followed by some more non-printables.
|
|
45
|
-
mode = PARSE_ESC
|
|
46
|
-
when ZWJ # non-printable, followed by another non-printable.
|
|
47
|
-
mode = PARSE_ZWJ
|
|
48
|
-
else
|
|
49
|
-
width += width(cp)
|
|
50
|
-
if width >= printing_width
|
|
51
|
-
truncation_index ||= index
|
|
52
|
-
# it looks like we could break here but we still want the
|
|
53
|
-
# width calculation for the rest of the characters.
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
when PARSE_ESC
|
|
57
|
-
mode = case cp
|
|
58
|
-
when LEFT_SQUARE_BRACKET
|
|
59
|
-
PARSE_ANSI
|
|
60
|
-
else
|
|
61
|
-
PARSE_ROOT
|
|
62
|
-
end
|
|
63
|
-
when PARSE_ANSI
|
|
64
|
-
# ANSI escape codes preeeetty much have the format of:
|
|
65
|
-
# \x1b[0-9;]+[A-Za-z]
|
|
66
|
-
case cp
|
|
67
|
-
when NUMERIC_RANGE, SEMICOLON
|
|
68
|
-
when LC_ALPHA_RANGE, UC_ALPHA_RANGE
|
|
69
|
-
mode = PARSE_ROOT
|
|
70
|
-
else
|
|
71
|
-
# unexpected. let's just go back to the root state I guess?
|
|
72
|
-
mode = PARSE_ROOT
|
|
73
|
-
end
|
|
74
|
-
when PARSE_ZWJ
|
|
75
|
-
# consume any character and consider it as having no width
|
|
76
|
-
# width(x+ZWJ+y) = width(x).
|
|
77
|
-
mode = PARSE_ROOT
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Without the `width <= printing_width` check, we truncate
|
|
82
|
-
# "foo\x1b[0m" for a width of 3, but it should not be truncated.
|
|
83
|
-
# It's specifically for the case where we decided "Yes, this is the
|
|
84
|
-
# point at which we'd have to add a truncation!" but it's actually
|
|
85
|
-
# the end of the string.
|
|
86
|
-
return text if !truncation_index || width <= printing_width
|
|
87
|
-
|
|
88
|
-
slice = codepoints[0...truncation_index] #: as !nil
|
|
89
|
-
slice.pack('U*') + TRUNCATED
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
#: (Integer printable_codepoint) -> Integer
|
|
95
|
-
def width(printable_codepoint)
|
|
96
|
-
case printable_codepoint
|
|
97
|
-
when EMOJI_RANGE
|
|
98
|
-
2
|
|
99
|
-
else
|
|
100
|
-
1
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require('cli/ui')
|
|
5
|
-
|
|
6
|
-
module CLI
|
|
7
|
-
module UI
|
|
8
|
-
module Widgets
|
|
9
|
-
# @abstract
|
|
10
|
-
class Base
|
|
11
|
-
class << self
|
|
12
|
-
#: (String argstring) -> String
|
|
13
|
-
def call(argstring)
|
|
14
|
-
new(argstring).render
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
#: (String argstring) -> void
|
|
19
|
-
def initialize(argstring)
|
|
20
|
-
pat = self.class.argparse_pattern
|
|
21
|
-
unless (@match_data = pat.match(argstring))
|
|
22
|
-
raise(Widgets::InvalidWidgetArguments.new(argstring, pat))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
@match_data.names.each do |name|
|
|
26
|
-
instance_variable_set(:"@#{name}", @match_data[name])
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class << self
|
|
31
|
-
# @abstract
|
|
32
|
-
#: -> Regexp
|
|
33
|
-
def argparse_pattern
|
|
34
|
-
raise(NotImplementedError)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @abstract
|
|
39
|
-
#: -> String
|
|
40
|
-
def render
|
|
41
|
-
raise(NotImplementedError)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|