fluid_cli 0.1.2
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 +7 -0
- data/README.md +1 -0
- data/dev.yml +5 -0
- data/exe/fluid +24 -0
- data/lib/fluid_cli/api.rb +135 -0
- data/lib/fluid_cli/assets/post_auth_page/index.html.erb +34 -0
- data/lib/fluid_cli/assets/post_auth_page/style.css +58 -0
- data/lib/fluid_cli/command.rb +55 -0
- data/lib/fluid_cli/commands/help.rb +21 -0
- data/lib/fluid_cli/commands/login.rb +30 -0
- data/lib/fluid_cli/commands/logout.rb +38 -0
- data/lib/fluid_cli/commands/switch.rb +23 -0
- data/lib/fluid_cli/commands/theme/common/company_helper.rb +15 -0
- data/lib/fluid_cli/commands/theme/common/root_helper.rb +95 -0
- data/lib/fluid_cli/commands/theme/dev.rb +61 -0
- data/lib/fluid_cli/commands/theme/help.rb +21 -0
- data/lib/fluid_cli/commands/theme/init.rb +46 -0
- data/lib/fluid_cli/commands/theme/pull.rb +68 -0
- data/lib/fluid_cli/commands/theme/push.rb +132 -0
- data/lib/fluid_cli/commands/theme.rb +23 -0
- data/lib/fluid_cli/commands/whoami.rb +23 -0
- data/lib/fluid_cli/commands.rb +19 -0
- data/lib/fluid_cli/company_switcher.rb +69 -0
- data/lib/fluid_cli/context.rb +691 -0
- data/lib/fluid_cli/db.rb +114 -0
- data/lib/fluid_cli/entry_point.rb +10 -0
- data/lib/fluid_cli/environment.rb +32 -0
- data/lib/fluid_cli/file_system_listener.rb +29 -0
- data/lib/fluid_cli/form.rb +42 -0
- data/lib/fluid_cli/git.rb +319 -0
- data/lib/fluid_cli/http_request.rb +54 -0
- data/lib/fluid_cli/identity_auth/servlet.rb +39 -0
- data/lib/fluid_cli/identity_auth.rb +126 -0
- data/lib/fluid_cli/options.rb +38 -0
- data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +79 -0
- data/lib/fluid_cli/theme/dev_server/errors.rb +9 -0
- data/lib/fluid_cli/theme/dev_server/header_hash.rb +98 -0
- data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +39 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +27 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +28 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +43 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +16 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +54 -0
- data/lib/fluid_cli/theme/dev_server/hot_reload.rb +75 -0
- data/lib/fluid_cli/theme/dev_server/local_assets.rb +92 -0
- data/lib/fluid_cli/theme/dev_server/proxy.rb +235 -0
- data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +82 -0
- data/lib/fluid_cli/theme/dev_server/reload_mode.rb +34 -0
- data/lib/fluid_cli/theme/dev_server/sse.rb +75 -0
- data/lib/fluid_cli/theme/dev_server/watcher.rb +57 -0
- data/lib/fluid_cli/theme/dev_server/web_server.rb +140 -0
- data/lib/fluid_cli/theme/dev_server.rb +289 -0
- data/lib/fluid_cli/theme/development_theme.rb +101 -0
- data/lib/fluid_cli/theme/file.rb +105 -0
- data/lib/fluid_cli/theme/forms/select.rb +33 -0
- data/lib/fluid_cli/theme/mime_type.rb +34 -0
- data/lib/fluid_cli/theme/presenters/theme_presenter.rb +49 -0
- data/lib/fluid_cli/theme/presenters/themes_presenter.rb +31 -0
- data/lib/fluid_cli/theme/root.rb +62 -0
- data/lib/fluid_cli/theme/syncer/checksums.rb +66 -0
- data/lib/fluid_cli/theme/syncer/downloader.rb +54 -0
- data/lib/fluid_cli/theme/syncer/error_reporter.rb +45 -0
- data/lib/fluid_cli/theme/syncer/merger.rb +53 -0
- data/lib/fluid_cli/theme/syncer/operation.rb +58 -0
- data/lib/fluid_cli/theme/syncer/standard_reporter.rb +32 -0
- data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +90 -0
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +41 -0
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +37 -0
- data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +64 -0
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +29 -0
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +30 -0
- data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +49 -0
- data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +71 -0
- data/lib/fluid_cli/theme/syncer/uploader.rb +105 -0
- data/lib/fluid_cli/theme/syncer.rb +412 -0
- data/lib/fluid_cli/theme/theme.rb +186 -0
- data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +22 -0
- data/lib/fluid_cli/thread_pool/job.rb +35 -0
- data/lib/fluid_cli/thread_pool.rb +49 -0
- data/lib/fluid_cli/version.rb +3 -0
- data/lib/fluid_cli.rb +59 -0
- data/vendor/deps/base64/.document +5 -0
- data/vendor/deps/base64/.gitignore +9 -0
- data/vendor/deps/base64/BSDL +22 -0
- data/vendor/deps/base64/COPYING +56 -0
- data/vendor/deps/base64/Gemfile +9 -0
- data/vendor/deps/base64/LEGAL +60 -0
- data/vendor/deps/base64/README.md +48 -0
- data/vendor/deps/base64/Rakefile +31 -0
- data/vendor/deps/base64/base64.gemspec +28 -0
- data/vendor/deps/base64/bin/console +14 -0
- data/vendor/deps/base64/bin/setup +8 -0
- data/vendor/deps/base64/lib/base64.rb +382 -0
- data/vendor/deps/base64/sig/base64.rbs +358 -0
- data/vendor/deps/base64/test/base64/test_base64.rb +115 -0
- data/vendor/deps/base64/test_sig/test_base64.rb +44 -0
- data/vendor/deps/cli-kit/REVISION +1 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +286 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +215 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +128 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +125 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +130 -0
- data/vendor/deps/cli-kit/lib/cli/kit/args.rb +16 -0
- data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +30 -0
- data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +268 -0
- data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +150 -0
- data/vendor/deps/cli-kit/lib/cli/kit/config.rb +137 -0
- data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +28 -0
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +166 -0
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +92 -0
- data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +91 -0
- data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +92 -0
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +94 -0
- data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +248 -0
- data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +55 -0
- data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +66 -0
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +260 -0
- data/vendor/deps/cli-kit/lib/cli/kit/support.rb +11 -0
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +290 -0
- data/vendor/deps/cli-kit/lib/cli/kit/util.rb +118 -0
- data/vendor/deps/cli-kit/lib/cli/kit/version.rb +7 -0
- data/vendor/deps/cli-kit/lib/cli/kit.rb +139 -0
- data/vendor/deps/cli-ui/REVISION +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +218 -0
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +101 -0
- data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +219 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +67 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +179 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +152 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +127 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +286 -0
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +92 -0
- data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
- data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +64 -0
- data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +132 -0
- data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +209 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +583 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +36 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +381 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +48 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +602 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +79 -0
- data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +399 -0
- data/vendor/deps/cli-ui/lib/cli/ui/table.rb +83 -0
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +55 -0
- data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +106 -0
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +8 -0
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +46 -0
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +79 -0
- data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +89 -0
- data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +142 -0
- data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +61 -0
- data/vendor/deps/cli-ui/lib/cli/ui.rb +359 -0
- data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +78 -0
- data/vendor/deps/debug/CONTRIBUTING.md +573 -0
- data/vendor/deps/debug/Gemfile +10 -0
- data/vendor/deps/debug/LICENSE.txt +22 -0
- data/vendor/deps/debug/README.md +996 -0
- data/vendor/deps/debug/Rakefile +57 -0
- data/vendor/deps/debug/TODO.md +23 -0
- data/vendor/deps/debug/debug.gemspec +33 -0
- data/vendor/deps/debug/exe/rdbg +53 -0
- data/vendor/deps/debug/ext/debug/Makefile +273 -0
- data/vendor/deps/debug/ext/debug/debug.c +228 -0
- data/vendor/deps/debug/ext/debug/debug_version.h +1 -0
- data/vendor/deps/debug/ext/debug/extconf.rb +27 -0
- data/vendor/deps/debug/ext/debug/iseq_collector.c +93 -0
- data/vendor/deps/debug/lib/debug/abbrev_command.rb +77 -0
- data/vendor/deps/debug/lib/debug/breakpoint.rb +556 -0
- data/vendor/deps/debug/lib/debug/client.rb +263 -0
- data/vendor/deps/debug/lib/debug/color.rb +123 -0
- data/vendor/deps/debug/lib/debug/config.rb +592 -0
- data/vendor/deps/debug/lib/debug/console.rb +224 -0
- data/vendor/deps/debug/lib/debug/dap_custom/traceInspector.rb +336 -0
- data/vendor/deps/debug/lib/debug/debug.bundle +0 -0
- data/vendor/deps/debug/lib/debug/frame_info.rb +190 -0
- data/vendor/deps/debug/lib/debug/irb_integration.rb +37 -0
- data/vendor/deps/debug/lib/debug/local.rb +115 -0
- data/vendor/deps/debug/lib/debug/open.rb +13 -0
- data/vendor/deps/debug/lib/debug/open_nonstop.rb +15 -0
- data/vendor/deps/debug/lib/debug/prelude.rb +50 -0
- data/vendor/deps/debug/lib/debug/server.rb +534 -0
- data/vendor/deps/debug/lib/debug/server_cdp.rb +1348 -0
- data/vendor/deps/debug/lib/debug/server_dap.rb +1108 -0
- data/vendor/deps/debug/lib/debug/session.rb +2667 -0
- data/vendor/deps/debug/lib/debug/source_repository.rb +150 -0
- data/vendor/deps/debug/lib/debug/start.rb +5 -0
- data/vendor/deps/debug/lib/debug/thread_client.rb +1457 -0
- data/vendor/deps/debug/lib/debug/tracer.rb +241 -0
- data/vendor/deps/debug/lib/debug/version.rb +5 -0
- data/vendor/deps/debug/lib/debug.rb +9 -0
- data/vendor/deps/debug/misc/README.md.erb +660 -0
- data/vendor/deps/listen/.github/release-drafter.yml +17 -0
- data/vendor/deps/listen/.github/workflows/development.yml +67 -0
- data/vendor/deps/listen/.github/workflows/push.yml +12 -0
- data/vendor/deps/listen/.gitignore +28 -0
- data/vendor/deps/listen/.rspec +3 -0
- data/vendor/deps/listen/.rubocop.yml +283 -0
- data/vendor/deps/listen/.yardopts +11 -0
- data/vendor/deps/listen/CHANGELOG.md +1 -0
- data/vendor/deps/listen/CONTRIBUTING.md +45 -0
- data/vendor/deps/listen/Gemfile +33 -0
- data/vendor/deps/listen/Guardfile +26 -0
- data/vendor/deps/listen/LICENSE.txt +22 -0
- data/vendor/deps/listen/README.md +490 -0
- data/vendor/deps/listen/Rakefile +154 -0
- data/vendor/deps/listen/bin/listen +11 -0
- data/vendor/deps/listen/lib/listen/adapter/base.rb +129 -0
- data/vendor/deps/listen/lib/listen/adapter/bsd.rb +104 -0
- data/vendor/deps/listen/lib/listen/adapter/config.rb +31 -0
- data/vendor/deps/listen/lib/listen/adapter/darwin.rb +77 -0
- data/vendor/deps/listen/lib/listen/adapter/linux.rb +108 -0
- data/vendor/deps/listen/lib/listen/adapter/polling.rb +40 -0
- data/vendor/deps/listen/lib/listen/adapter/windows.rb +96 -0
- data/vendor/deps/listen/lib/listen/adapter.rb +43 -0
- data/vendor/deps/listen/lib/listen/backend.rb +40 -0
- data/vendor/deps/listen/lib/listen/change.rb +69 -0
- data/vendor/deps/listen/lib/listen/cli.rb +65 -0
- data/vendor/deps/listen/lib/listen/directory.rb +93 -0
- data/vendor/deps/listen/lib/listen/error.rb +11 -0
- data/vendor/deps/listen/lib/listen/event/config.rb +39 -0
- data/vendor/deps/listen/lib/listen/event/loop.rb +92 -0
- data/vendor/deps/listen/lib/listen/event/processor.rb +128 -0
- data/vendor/deps/listen/lib/listen/event/queue.rb +52 -0
- data/vendor/deps/listen/lib/listen/file.rb +95 -0
- data/vendor/deps/listen/lib/listen/fsm.rb +131 -0
- data/vendor/deps/listen/lib/listen/listener/config.rb +41 -0
- data/vendor/deps/listen/lib/listen/listener.rb +136 -0
- data/vendor/deps/listen/lib/listen/logger.rb +65 -0
- data/vendor/deps/listen/lib/listen/monotonic_time.rb +27 -0
- data/vendor/deps/listen/lib/listen/options.rb +24 -0
- data/vendor/deps/listen/lib/listen/queue_optimizer.rb +129 -0
- data/vendor/deps/listen/lib/listen/record/entry.rb +66 -0
- data/vendor/deps/listen/lib/listen/record/symlink_detector.rb +47 -0
- data/vendor/deps/listen/lib/listen/record.rb +122 -0
- data/vendor/deps/listen/lib/listen/silencer/controller.rb +50 -0
- data/vendor/deps/listen/lib/listen/silencer.rb +106 -0
- data/vendor/deps/listen/lib/listen/thread.rb +54 -0
- data/vendor/deps/listen/lib/listen/version.rb +5 -0
- data/vendor/deps/listen/lib/listen.rb +47 -0
- data/vendor/deps/listen/listen.gemspec +40 -0
- data/vendor/deps/listen/spec/acceptance/listen_spec.rb +320 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/base_spec.rb +101 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/bsd_spec.rb +13 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/config_spec.rb +122 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/darwin_spec.rb +82 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/linux_spec.rb +199 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/polling_spec.rb +83 -0
- data/vendor/deps/listen/spec/lib/listen/adapter/windows_spec.rb +13 -0
- data/vendor/deps/listen/spec/lib/listen/adapter_spec.rb +69 -0
- data/vendor/deps/listen/spec/lib/listen/backend_spec.rb +82 -0
- data/vendor/deps/listen/spec/lib/listen/change_spec.rb +102 -0
- data/vendor/deps/listen/spec/lib/listen/cli_spec.rb +116 -0
- data/vendor/deps/listen/spec/lib/listen/directory_spec.rb +284 -0
- data/vendor/deps/listen/spec/lib/listen/event/config_spec.rb +33 -0
- data/vendor/deps/listen/spec/lib/listen/event/loop_spec.rb +118 -0
- data/vendor/deps/listen/spec/lib/listen/event/processor_spec.rb +250 -0
- data/vendor/deps/listen/spec/lib/listen/event/queue_spec.rb +118 -0
- data/vendor/deps/listen/spec/lib/listen/file_spec.rb +254 -0
- data/vendor/deps/listen/spec/lib/listen/fsm_spec.rb +147 -0
- data/vendor/deps/listen/spec/lib/listen/listener/config_spec.rb +29 -0
- data/vendor/deps/listen/spec/lib/listen/listener_spec.rb +321 -0
- data/vendor/deps/listen/spec/lib/listen/logger_spec.rb +212 -0
- data/vendor/deps/listen/spec/lib/listen/monotonic_time_spec.rb +58 -0
- data/vendor/deps/listen/spec/lib/listen/queue_optimizer_spec.rb +111 -0
- data/vendor/deps/listen/spec/lib/listen/record_spec.rb +424 -0
- data/vendor/deps/listen/spec/lib/listen/silencer/controller_spec.rb +97 -0
- data/vendor/deps/listen/spec/lib/listen/silencer_spec.rb +109 -0
- data/vendor/deps/listen/spec/lib/listen/thread_spec.rb +133 -0
- data/vendor/deps/listen/spec/lib/listen_spec.rb +25 -0
- data/vendor/deps/listen/spec/spec_helper.rb +49 -0
- data/vendor/deps/listen/spec/support/acceptance_helper.rb +260 -0
- data/vendor/deps/listen/spec/support/fixtures_helper.rb +32 -0
- data/vendor/deps/listen/spec/support/platform_helper.rb +17 -0
- data/vendor/deps/observer/.github/dependabot.yml +6 -0
- data/vendor/deps/observer/.github/workflows/test.yml +33 -0
- data/vendor/deps/observer/.gitignore +8 -0
- data/vendor/deps/observer/BSDL +22 -0
- data/vendor/deps/observer/COPYING +56 -0
- data/vendor/deps/observer/Gemfile +9 -0
- data/vendor/deps/observer/README.md +139 -0
- data/vendor/deps/observer/Rakefile +10 -0
- data/vendor/deps/observer/bin/console +14 -0
- data/vendor/deps/observer/bin/setup +8 -0
- data/vendor/deps/observer/lib/observer.rb +229 -0
- data/vendor/deps/observer/observer.gemspec +32 -0
- data/vendor/deps/observer/test/test_observer.rb +66 -0
- data/vendor/deps/webrick/.gitignore +9 -0
- data/vendor/deps/webrick/Gemfile +3 -0
- data/vendor/deps/webrick/LICENSE.txt +22 -0
- data/vendor/deps/webrick/README.md +61 -0
- data/vendor/deps/webrick/Rakefile +10 -0
- data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
- data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
- data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
- data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
- data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
- data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
- data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
- data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
- data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
- data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
- data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
- data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
- data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
- data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
- data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
- data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
- data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
- data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
- data/vendor/deps/webrick/lib/webrick.rb +232 -0
- data/vendor/deps/webrick/webrick.gemspec +74 -0
- metadata +412 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
|
|
3
|
+
require 'cli/ui'
|
|
4
|
+
require 'cli/kit/core_ext'
|
|
5
|
+
|
|
6
|
+
module CLI
|
|
7
|
+
module Kit
|
|
8
|
+
autoload :Args, 'cli/kit/args'
|
|
9
|
+
autoload :BaseCommand, 'cli/kit/base_command'
|
|
10
|
+
autoload :CommandRegistry, 'cli/kit/command_registry'
|
|
11
|
+
autoload :CommandHelp, 'cli/kit/command_help'
|
|
12
|
+
autoload :Config, 'cli/kit/config'
|
|
13
|
+
autoload :ErrorHandler, 'cli/kit/error_handler'
|
|
14
|
+
autoload :Executor, 'cli/kit/executor'
|
|
15
|
+
autoload :Ini, 'cli/kit/ini'
|
|
16
|
+
autoload :Levenshtein, 'cli/kit/levenshtein'
|
|
17
|
+
autoload :Logger, 'cli/kit/logger'
|
|
18
|
+
autoload :Opts, 'cli/kit/opts'
|
|
19
|
+
autoload :ParseArgs, 'cli/kit/parse_args'
|
|
20
|
+
autoload :Resolver, 'cli/kit/resolver'
|
|
21
|
+
autoload :Support, 'cli/kit/support'
|
|
22
|
+
autoload :System, 'cli/kit/system'
|
|
23
|
+
autoload :Util, 'cli/kit/util'
|
|
24
|
+
|
|
25
|
+
EXIT_FAILURE_BUT_NOT_BUG = 30
|
|
26
|
+
EXIT_BUG = 1
|
|
27
|
+
EXIT_SUCCESS = 0
|
|
28
|
+
|
|
29
|
+
UNTYPED_NIL = nil #: untyped
|
|
30
|
+
private_constant(:UNTYPED_NIL)
|
|
31
|
+
|
|
32
|
+
# Abort, Bug, AbortSilent, and BugSilent are four ways of immediately bailing
|
|
33
|
+
# on command-line execution when an unrecoverable error occurs.
|
|
34
|
+
#
|
|
35
|
+
# Note that these don't inherit from StandardError, and so are not caught by
|
|
36
|
+
# a bare `rescue => e`.
|
|
37
|
+
#
|
|
38
|
+
# * Abort prints its message in red and exits 1;
|
|
39
|
+
# * Bug additionally submits the exception to the exception_reporter passed to
|
|
40
|
+
# `CLI::Kit::ErrorHandler.new`
|
|
41
|
+
# * AbortSilent and BugSilent do the same as above, but do not print
|
|
42
|
+
# messages before exiting.
|
|
43
|
+
#
|
|
44
|
+
# Treat these like panic() in Go:
|
|
45
|
+
# * Don't rescue them. Use a different Exception class if you plan to recover;
|
|
46
|
+
# * Provide a useful message, since it will be presented in brief to the
|
|
47
|
+
# user, and will be useful for debugging.
|
|
48
|
+
# * Avoid using it if it does actually make sense to recover from an error.
|
|
49
|
+
#
|
|
50
|
+
# Additionally:
|
|
51
|
+
# * Do not subclass these.
|
|
52
|
+
# * Only use AbortSilent or BugSilent if you prefer to print a more
|
|
53
|
+
# contextualized error than Abort or Bug would present to the user.
|
|
54
|
+
# * In general, don't attach a message to AbortSilent or BugSilent.
|
|
55
|
+
# * Never raise GenericAbort directly.
|
|
56
|
+
# * Think carefully about whether Abort or Bug is more appropriate. Is this
|
|
57
|
+
# a bug in the tool? Or is it just user error, transient network
|
|
58
|
+
# failure, etc.?
|
|
59
|
+
# * One case where it's ok to rescue (cli-kit internals or tests aside):
|
|
60
|
+
# 1. rescue Abort or Bug
|
|
61
|
+
# 2. Print a contextualized error message
|
|
62
|
+
# 3. Re-raise AbortSilent or BugSilent respectively.
|
|
63
|
+
#
|
|
64
|
+
# These aren't the only exceptions that can carry this 'bug' and 'silent'
|
|
65
|
+
# metadata, however:
|
|
66
|
+
#
|
|
67
|
+
# If you raise an exception with `CLI::Kit.raise(..., bug: x, silent: y)`,
|
|
68
|
+
# those last two (optional) keyword arguments will attach the metadata to
|
|
69
|
+
# whatever exception you raise. This is interpreted later in the
|
|
70
|
+
# ErrorHandler to decide how to print output and whether to submit the
|
|
71
|
+
# exception to bugsnag.
|
|
72
|
+
GenericAbort = Class.new(Exception) # rubocop:disable Lint/InheritException
|
|
73
|
+
|
|
74
|
+
class Abort < GenericAbort # bug:false; silent: false
|
|
75
|
+
#: -> bool
|
|
76
|
+
def bug?
|
|
77
|
+
false
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Bug < GenericAbort # bug:true; silent:false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
class BugSilent < GenericAbort # bug:true; silent:true
|
|
85
|
+
#: -> bool
|
|
86
|
+
def silent?
|
|
87
|
+
true
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class AbortSilent < GenericAbort # bug:false; silent:true
|
|
92
|
+
#: -> bool
|
|
93
|
+
def bug?
|
|
94
|
+
false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#: -> bool
|
|
98
|
+
def silent?
|
|
99
|
+
true
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class << self
|
|
104
|
+
# Mirrors the API of Kernel#raise, but with the addition of a few new
|
|
105
|
+
# optional keyword arguments. `bug` and `silent` attach metadata to the
|
|
106
|
+
# exception being raised, which is interpreted later in the ErrorHandler to
|
|
107
|
+
# decide what to print and whether to submit to bugsnag.
|
|
108
|
+
#
|
|
109
|
+
# `depth` is used to trim leading elements of the backtrace. If you wrap
|
|
110
|
+
# this method in your own wrapper, you'll want to pass `depth: 2`, for
|
|
111
|
+
# example.
|
|
112
|
+
#: (?(Class | String | Exception) exception, ?untyped string, ?Array[String]? array, ?cause: Exception?, ?bug: bool?, ?silent: bool?, ?depth: Integer) -> bot
|
|
113
|
+
def raise(
|
|
114
|
+
# default arguments
|
|
115
|
+
exception = UNTYPED_NIL,
|
|
116
|
+
string = UNTYPED_NIL,
|
|
117
|
+
array = UNTYPED_NIL,
|
|
118
|
+
cause: $ERROR_INFO,
|
|
119
|
+
# new arguments
|
|
120
|
+
bug: nil, silent: nil, depth: 1
|
|
121
|
+
)
|
|
122
|
+
k = Kernel #: as untyped
|
|
123
|
+
if array
|
|
124
|
+
k.raise(exception, string, array, cause: cause)
|
|
125
|
+
elsif string
|
|
126
|
+
k.raise(exception, string, Kernel.caller(depth), cause: cause)
|
|
127
|
+
elsif exception.is_a?(String)
|
|
128
|
+
k.raise(RuntimeError, exception, Kernel.caller(depth), cause: cause)
|
|
129
|
+
else
|
|
130
|
+
k.raise(exception, exception.message, Kernel.caller(depth), cause: cause)
|
|
131
|
+
end
|
|
132
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
133
|
+
e.bug!(bug) unless bug.nil?
|
|
134
|
+
e.silent!(silent) unless silent.nil?
|
|
135
|
+
Kernel.raise(e, cause: cause)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
53b30b0786fd3db544ae80ae641e88f126006b88
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'cli/ui'
|
|
5
|
+
|
|
6
|
+
module CLI
|
|
7
|
+
module UI
|
|
8
|
+
module ANSI
|
|
9
|
+
ESC = "\x1b"
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
# ANSI escape sequences (like \x1b[31m) have zero width.
|
|
13
|
+
# when calculating the padding width, we must exclude them.
|
|
14
|
+
# This also implements a basic version of utf8 character width calculation like
|
|
15
|
+
# we could get for real from something like utf8proc.
|
|
16
|
+
#
|
|
17
|
+
#: (String str) -> Integer
|
|
18
|
+
def printing_width(str)
|
|
19
|
+
zwj = false #: bool
|
|
20
|
+
strip_codes(str).codepoints.reduce(0) do |acc, cp|
|
|
21
|
+
if zwj
|
|
22
|
+
zwj = false
|
|
23
|
+
next acc
|
|
24
|
+
end
|
|
25
|
+
case cp
|
|
26
|
+
when 0x200d # zero-width joiner
|
|
27
|
+
zwj = true
|
|
28
|
+
acc
|
|
29
|
+
when "\n"
|
|
30
|
+
acc
|
|
31
|
+
else
|
|
32
|
+
acc + 1
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Strips ANSI codes from a str
|
|
38
|
+
#
|
|
39
|
+
# ==== Attributes
|
|
40
|
+
#
|
|
41
|
+
# - +str+ - The string from which to strip codes
|
|
42
|
+
#
|
|
43
|
+
#: (String str) -> String
|
|
44
|
+
def strip_codes(str)
|
|
45
|
+
str.gsub(/\x1b\[[\d;]+[A-Za-z]|\x1b\][\d;]+.*?\x1b\\|\r/, '')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Returns an ANSI control sequence
|
|
49
|
+
#
|
|
50
|
+
# ==== Attributes
|
|
51
|
+
#
|
|
52
|
+
# - +args+ - Argument to pass to the ANSI control sequence
|
|
53
|
+
# - +cmd+ - ANSI control sequence Command
|
|
54
|
+
#
|
|
55
|
+
#: (String args, String cmd) -> String
|
|
56
|
+
def control(args, cmd)
|
|
57
|
+
ESC + '[' + args + cmd
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# https://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
61
|
+
#: (String params) -> String
|
|
62
|
+
def sgr(params)
|
|
63
|
+
control(params, 'm')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Cursor Movement
|
|
67
|
+
|
|
68
|
+
# Move the cursor up n lines
|
|
69
|
+
#
|
|
70
|
+
# ==== Attributes
|
|
71
|
+
#
|
|
72
|
+
# * +n+ - number of lines by which to move the cursor up
|
|
73
|
+
#
|
|
74
|
+
#: (?Integer n) -> String
|
|
75
|
+
def cursor_up(n = 1)
|
|
76
|
+
return '' if n.zero?
|
|
77
|
+
|
|
78
|
+
control(n.to_s, 'A')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Move the cursor down n lines
|
|
82
|
+
#
|
|
83
|
+
# ==== Attributes
|
|
84
|
+
#
|
|
85
|
+
# * +n+ - number of lines by which to move the cursor down
|
|
86
|
+
#
|
|
87
|
+
#: (?Integer n) -> String
|
|
88
|
+
def cursor_down(n = 1)
|
|
89
|
+
return '' if n.zero?
|
|
90
|
+
|
|
91
|
+
control(n.to_s, 'B')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Move the cursor forward n columns
|
|
95
|
+
#
|
|
96
|
+
# ==== Attributes
|
|
97
|
+
#
|
|
98
|
+
# * +n+ - number of columns by which to move the cursor forward
|
|
99
|
+
#
|
|
100
|
+
#: (?Integer n) -> String
|
|
101
|
+
def cursor_forward(n = 1)
|
|
102
|
+
return '' if n.zero?
|
|
103
|
+
|
|
104
|
+
control(n.to_s, 'C')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Move the cursor back n columns
|
|
108
|
+
#
|
|
109
|
+
# ==== Attributes
|
|
110
|
+
#
|
|
111
|
+
# * +n+ - number of columns by which to move the cursor back
|
|
112
|
+
#
|
|
113
|
+
#: (?Integer n) -> String
|
|
114
|
+
def cursor_back(n = 1)
|
|
115
|
+
return '' if n.zero?
|
|
116
|
+
|
|
117
|
+
control(n.to_s, 'D')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Move the cursor to a specific column
|
|
121
|
+
#
|
|
122
|
+
# ==== Attributes
|
|
123
|
+
#
|
|
124
|
+
# * +n+ - The column to move to
|
|
125
|
+
#
|
|
126
|
+
#: (?Integer n) -> String
|
|
127
|
+
def cursor_horizontal_absolute(n = 1)
|
|
128
|
+
cmd = control(n.to_s, 'G')
|
|
129
|
+
cmd += cursor_back if CLI::UI::OS.current.shift_cursor_back_on_horizontal_absolute?
|
|
130
|
+
cmd
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#: -> String
|
|
134
|
+
def enter_alternate_screen
|
|
135
|
+
control('?1049', 'h')
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#: -> String
|
|
139
|
+
def exit_alternate_screen
|
|
140
|
+
control('?1049', 'l')
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
#: -> Regexp
|
|
144
|
+
def match_alternate_screen
|
|
145
|
+
/#{Regexp.escape(control("?1049", ""))}[hl]/
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Show the cursor
|
|
149
|
+
#
|
|
150
|
+
#: -> String
|
|
151
|
+
def show_cursor
|
|
152
|
+
control('', '?25h')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Hide the cursor
|
|
156
|
+
#
|
|
157
|
+
#: -> String
|
|
158
|
+
def hide_cursor
|
|
159
|
+
control('', '?25l')
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Save the cursor position
|
|
163
|
+
#
|
|
164
|
+
#: -> String
|
|
165
|
+
def cursor_save
|
|
166
|
+
control('', 's')
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Restore the saved cursor position
|
|
170
|
+
#
|
|
171
|
+
#: -> String
|
|
172
|
+
def cursor_restore
|
|
173
|
+
control('', 'u')
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Move to the next line
|
|
177
|
+
#
|
|
178
|
+
#: -> String
|
|
179
|
+
def next_line
|
|
180
|
+
cursor_down + cursor_horizontal_absolute
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Move to the previous line
|
|
184
|
+
#
|
|
185
|
+
#: -> String
|
|
186
|
+
def previous_line
|
|
187
|
+
previous_lines(1)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Move to the previous n lines
|
|
191
|
+
#
|
|
192
|
+
# ==== Attributes
|
|
193
|
+
#
|
|
194
|
+
# * +n+ - number of lines by which to move the cursor up
|
|
195
|
+
#
|
|
196
|
+
#: (?Integer n) -> String
|
|
197
|
+
def previous_lines(n = 1)
|
|
198
|
+
cursor_up(n) + cursor_horizontal_absolute
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
#: -> String
|
|
202
|
+
def clear_to_end_of_line
|
|
203
|
+
control('', 'K')
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
#: -> String
|
|
207
|
+
def insert_line
|
|
208
|
+
insert_lines(1)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#: (?Integer n) -> String
|
|
212
|
+
def insert_lines(n = 1)
|
|
213
|
+
control(n.to_s, 'L')
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'cli/ui'
|
|
5
|
+
|
|
6
|
+
module CLI
|
|
7
|
+
module UI
|
|
8
|
+
class Color
|
|
9
|
+
#: String
|
|
10
|
+
attr_reader :sgr, :code
|
|
11
|
+
|
|
12
|
+
#: Symbol
|
|
13
|
+
attr_reader :name
|
|
14
|
+
|
|
15
|
+
# Creates a new color mapping
|
|
16
|
+
# Signatures can be found here:
|
|
17
|
+
# https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
18
|
+
#
|
|
19
|
+
# ==== Attributes
|
|
20
|
+
#
|
|
21
|
+
# * +sgr+ - The color signature
|
|
22
|
+
# * +name+ - The name of the color
|
|
23
|
+
#
|
|
24
|
+
#: (String sgr, Symbol name) -> void
|
|
25
|
+
def initialize(sgr, name)
|
|
26
|
+
@sgr = sgr
|
|
27
|
+
@code = CLI::UI::ANSI.sgr(sgr)
|
|
28
|
+
@name = name
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
RED = new('31', :red)
|
|
32
|
+
GREEN = new('32', :green)
|
|
33
|
+
YELLOW = new('33', :yellow)
|
|
34
|
+
# default blue is low-contrast against black in some default terminal color scheme
|
|
35
|
+
BLUE = new('94', :blue) # 9x = high-intensity fg color x
|
|
36
|
+
MAGENTA = new('35', :magenta)
|
|
37
|
+
CYAN = new('36', :cyan)
|
|
38
|
+
RESET = new('0', :reset)
|
|
39
|
+
BOLD = new('1', :bold)
|
|
40
|
+
WHITE = new('97', :white)
|
|
41
|
+
|
|
42
|
+
# 240 is very dark gray; 255 is very light gray. 244 is somewhat dark.
|
|
43
|
+
GRAY = new('38;5;244', :gray)
|
|
44
|
+
# Using color 214 from the 256-color palette for a more distinct orange
|
|
45
|
+
ORANGE = new('38;5;214', :orange)
|
|
46
|
+
|
|
47
|
+
MAP = {
|
|
48
|
+
red: RED,
|
|
49
|
+
green: GREEN,
|
|
50
|
+
yellow: YELLOW,
|
|
51
|
+
blue: BLUE,
|
|
52
|
+
magenta: MAGENTA,
|
|
53
|
+
cyan: CYAN,
|
|
54
|
+
reset: RESET,
|
|
55
|
+
bold: BOLD,
|
|
56
|
+
gray: GRAY,
|
|
57
|
+
orange: ORANGE,
|
|
58
|
+
}.freeze
|
|
59
|
+
|
|
60
|
+
class InvalidColorName < ArgumentError
|
|
61
|
+
#: (Symbol name) -> void
|
|
62
|
+
def initialize(name)
|
|
63
|
+
super
|
|
64
|
+
@name = name
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#: -> String
|
|
68
|
+
def message
|
|
69
|
+
keys = Color.available.map(&:inspect).join(',')
|
|
70
|
+
"invalid color: #{@name.inspect} " \
|
|
71
|
+
"-- must be one of CLI::UI::Color.available (#{keys})"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class << self
|
|
76
|
+
# Looks up a color code by name
|
|
77
|
+
#
|
|
78
|
+
# ==== Raises
|
|
79
|
+
# Raises a InvalidColorName if the color is not available
|
|
80
|
+
# You likely need to add it to the +MAP+ or you made a typo
|
|
81
|
+
#
|
|
82
|
+
# ==== Returns
|
|
83
|
+
# Returns a color code
|
|
84
|
+
#
|
|
85
|
+
#: ((Symbol | String) name) -> Color
|
|
86
|
+
def lookup(name)
|
|
87
|
+
MAP.fetch(name.to_sym)
|
|
88
|
+
rescue KeyError
|
|
89
|
+
raise InvalidColorName, name.to_sym
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# All available colors by name
|
|
93
|
+
#
|
|
94
|
+
#: -> Array[Symbol]
|
|
95
|
+
def available
|
|
96
|
+
MAP.keys
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require('cli/ui')
|
|
5
|
+
require('strscan')
|
|
6
|
+
|
|
7
|
+
module CLI
|
|
8
|
+
module UI
|
|
9
|
+
class Formatter
|
|
10
|
+
# Available mappings of formattings
|
|
11
|
+
# To use any of them, you can use {{<key>:<string>}}
|
|
12
|
+
# There are presentational (colours and formatters)
|
|
13
|
+
# and semantic (error, info, command) formatters available
|
|
14
|
+
#
|
|
15
|
+
SGR_MAP = {
|
|
16
|
+
# presentational
|
|
17
|
+
'red' => '31',
|
|
18
|
+
'green' => '32',
|
|
19
|
+
'yellow' => '33',
|
|
20
|
+
# default blue is low-contrast against black in some default terminal color scheme
|
|
21
|
+
'blue' => '94', # 9x = high-intensity fg color x
|
|
22
|
+
'magenta' => '35',
|
|
23
|
+
'cyan' => '36',
|
|
24
|
+
'gray' => '38;5;244',
|
|
25
|
+
'orange' => '38;5;214',
|
|
26
|
+
'white' => '97',
|
|
27
|
+
'bold' => '1',
|
|
28
|
+
'italic' => '3',
|
|
29
|
+
'underline' => '4',
|
|
30
|
+
'strikethrough' => '9',
|
|
31
|
+
'reset' => '0',
|
|
32
|
+
|
|
33
|
+
# semantic
|
|
34
|
+
'error' => '31', # red
|
|
35
|
+
'success' => '32', # success
|
|
36
|
+
'warning' => '33', # yellow
|
|
37
|
+
'info' => '94', # bright blue
|
|
38
|
+
'command' => '36', # cyan
|
|
39
|
+
}.freeze
|
|
40
|
+
|
|
41
|
+
BEGIN_EXPR = '{{'
|
|
42
|
+
END_EXPR = '}}'
|
|
43
|
+
|
|
44
|
+
SCAN_WIDGET = %r[@widget/(?<handle>\w+):(?<args>.*?)}}]
|
|
45
|
+
SCAN_FUNCNAME = /\w+:/
|
|
46
|
+
SCAN_GLYPH = /.}}/
|
|
47
|
+
SCAN_BODY = %r{
|
|
48
|
+
.*?
|
|
49
|
+
(
|
|
50
|
+
#{BEGIN_EXPR} |
|
|
51
|
+
#{END_EXPR} |
|
|
52
|
+
\z
|
|
53
|
+
)
|
|
54
|
+
}mx
|
|
55
|
+
|
|
56
|
+
DISCARD_BRACES = 0..-3
|
|
57
|
+
|
|
58
|
+
LITERAL_BRACES = Class.new
|
|
59
|
+
|
|
60
|
+
#: type stack = Array[String | LITERAL_BRACES]
|
|
61
|
+
|
|
62
|
+
class FormatError < StandardError
|
|
63
|
+
#: String
|
|
64
|
+
attr_accessor :input
|
|
65
|
+
|
|
66
|
+
#: Integer
|
|
67
|
+
attr_accessor :index
|
|
68
|
+
|
|
69
|
+
#: (String message, String input, Integer index) -> void
|
|
70
|
+
def initialize(message, input, index)
|
|
71
|
+
super(message)
|
|
72
|
+
@input = input
|
|
73
|
+
@index = index
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Initialize a formatter with text.
|
|
78
|
+
#
|
|
79
|
+
# ===== Attributes
|
|
80
|
+
#
|
|
81
|
+
# * +text+ - the text to format
|
|
82
|
+
#
|
|
83
|
+
#: (String text) -> void
|
|
84
|
+
def initialize(text)
|
|
85
|
+
@text = text
|
|
86
|
+
@nodes = [] #: Array[[String, stack]]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Format the text using a map.
|
|
90
|
+
#
|
|
91
|
+
# ===== Attributes
|
|
92
|
+
#
|
|
93
|
+
# * +sgr_map+ - the mapping of the formattings. Defaults to +SGR_MAP+
|
|
94
|
+
#
|
|
95
|
+
# ===== Options
|
|
96
|
+
#
|
|
97
|
+
# * +:enable_color+ - enable color output? Default is true unless output is redirected
|
|
98
|
+
#
|
|
99
|
+
#: (?Hash[String, String] sgr_map, ?enable_color: bool) -> String
|
|
100
|
+
def format(sgr_map = SGR_MAP, enable_color: CLI::UI.enable_color?)
|
|
101
|
+
@nodes.replace([])
|
|
102
|
+
stack = parse_body(StringScanner.new(@text))
|
|
103
|
+
prev_fmt = nil #: stack?
|
|
104
|
+
content = @nodes.each_with_object(+'') do |(text, fmt), str|
|
|
105
|
+
if prev_fmt != fmt && enable_color
|
|
106
|
+
text = apply_format(text, fmt, sgr_map)
|
|
107
|
+
end
|
|
108
|
+
str << text
|
|
109
|
+
prev_fmt = fmt
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
stack.reject! { |e| e.is_a?(LITERAL_BRACES) }
|
|
113
|
+
|
|
114
|
+
return content unless enable_color
|
|
115
|
+
return content if stack == prev_fmt
|
|
116
|
+
|
|
117
|
+
last_node = @nodes.last #: as !nil
|
|
118
|
+
unless stack.empty? && (@nodes.empty? || last_node[1].empty?)
|
|
119
|
+
content << apply_format('', stack, sgr_map)
|
|
120
|
+
end
|
|
121
|
+
content
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
private
|
|
125
|
+
|
|
126
|
+
#: (String text, stack fmt, Hash[String, String] sgr_map) -> String
|
|
127
|
+
def apply_format(text, fmt, sgr_map)
|
|
128
|
+
sgr = fmt.each_with_object(+'0') do |name, str|
|
|
129
|
+
next if name.is_a?(LITERAL_BRACES)
|
|
130
|
+
|
|
131
|
+
begin
|
|
132
|
+
str << ';' << sgr_map.fetch(name)
|
|
133
|
+
rescue KeyError
|
|
134
|
+
raise FormatError.new(
|
|
135
|
+
"invalid format specifier: #{name}",
|
|
136
|
+
@text,
|
|
137
|
+
-1,
|
|
138
|
+
)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
CLI::UI::ANSI.sgr(sgr) + text
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
#: (StringScanner sc, stack stack) -> stack
|
|
145
|
+
def parse_expr(sc, stack)
|
|
146
|
+
if (match = sc.scan(SCAN_GLYPH))
|
|
147
|
+
glyph_handle = match[0] #: as !nil
|
|
148
|
+
begin
|
|
149
|
+
glyph = Glyph.lookup(glyph_handle)
|
|
150
|
+
emit(glyph.char, [glyph.color.name.to_s])
|
|
151
|
+
rescue Glyph::InvalidGlyphHandle
|
|
152
|
+
index = sc.pos - 2 # rewind past '}}'
|
|
153
|
+
raise FormatError.new(
|
|
154
|
+
"invalid glyph handle at index #{index}: '#{glyph_handle}'",
|
|
155
|
+
@text,
|
|
156
|
+
index,
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
elsif (match = sc.scan(SCAN_WIDGET))
|
|
160
|
+
match_data = SCAN_WIDGET.match(match) #: as !nil # Regexp.last_match doesn't work here
|
|
161
|
+
widget_handle = match_data['handle'] #: as !nil
|
|
162
|
+
begin
|
|
163
|
+
widget = Widgets.lookup(widget_handle)
|
|
164
|
+
args = match_data['args'] #: as !nil
|
|
165
|
+
emit(widget.call(args), stack)
|
|
166
|
+
rescue Widgets::InvalidWidgetHandle
|
|
167
|
+
index = sc.pos - 2 # rewind past '}}'
|
|
168
|
+
raise(FormatError.new(
|
|
169
|
+
"invalid widget handle at index #{index}: '#{widget_handle}'",
|
|
170
|
+
@text,
|
|
171
|
+
index,
|
|
172
|
+
))
|
|
173
|
+
end
|
|
174
|
+
elsif (match = sc.scan(SCAN_FUNCNAME))
|
|
175
|
+
funcname = match.chop
|
|
176
|
+
stack.push(funcname)
|
|
177
|
+
else
|
|
178
|
+
# We read a {{ but it's not apparently Formatter syntax.
|
|
179
|
+
# We could error, but it's nicer to just pass through as text.
|
|
180
|
+
# We do kind of assume that the text will probably have balanced
|
|
181
|
+
# pairs of {{ }} at least.
|
|
182
|
+
emit('{{', stack)
|
|
183
|
+
stack.push(LITERAL_BRACES.new)
|
|
184
|
+
end
|
|
185
|
+
parse_body(sc, stack)
|
|
186
|
+
stack
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
#: (StringScanner sc, ?stack stack) -> stack
|
|
190
|
+
def parse_body(sc, stack = [])
|
|
191
|
+
match = sc.scan(SCAN_BODY)
|
|
192
|
+
if match&.end_with?(BEGIN_EXPR)
|
|
193
|
+
text = match[DISCARD_BRACES] #: as !nil
|
|
194
|
+
emit(text, stack)
|
|
195
|
+
parse_expr(sc, stack)
|
|
196
|
+
elsif match&.end_with?(END_EXPR)
|
|
197
|
+
text = match[DISCARD_BRACES] #: as !nil
|
|
198
|
+
emit(text, stack)
|
|
199
|
+
if stack.pop.is_a?(LITERAL_BRACES)
|
|
200
|
+
emit('}}', stack)
|
|
201
|
+
end
|
|
202
|
+
parse_body(sc, stack)
|
|
203
|
+
elsif match
|
|
204
|
+
emit(match, stack)
|
|
205
|
+
else
|
|
206
|
+
emit(sc.rest, stack)
|
|
207
|
+
end
|
|
208
|
+
stack
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#: (String text, stack stack) -> void
|
|
212
|
+
def emit(text, stack)
|
|
213
|
+
return if text.empty?
|
|
214
|
+
|
|
215
|
+
@nodes << [text, stack.reject { |n| n.is_a?(LITERAL_BRACES) }]
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|