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.
Files changed (329) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -0
  3. data/dev.yml +5 -0
  4. data/exe/fluid +24 -0
  5. data/lib/fluid_cli/api.rb +135 -0
  6. data/lib/fluid_cli/assets/post_auth_page/index.html.erb +34 -0
  7. data/lib/fluid_cli/assets/post_auth_page/style.css +58 -0
  8. data/lib/fluid_cli/command.rb +55 -0
  9. data/lib/fluid_cli/commands/help.rb +21 -0
  10. data/lib/fluid_cli/commands/login.rb +30 -0
  11. data/lib/fluid_cli/commands/logout.rb +38 -0
  12. data/lib/fluid_cli/commands/switch.rb +23 -0
  13. data/lib/fluid_cli/commands/theme/common/company_helper.rb +15 -0
  14. data/lib/fluid_cli/commands/theme/common/root_helper.rb +95 -0
  15. data/lib/fluid_cli/commands/theme/dev.rb +61 -0
  16. data/lib/fluid_cli/commands/theme/help.rb +21 -0
  17. data/lib/fluid_cli/commands/theme/init.rb +46 -0
  18. data/lib/fluid_cli/commands/theme/pull.rb +68 -0
  19. data/lib/fluid_cli/commands/theme/push.rb +132 -0
  20. data/lib/fluid_cli/commands/theme.rb +23 -0
  21. data/lib/fluid_cli/commands/whoami.rb +23 -0
  22. data/lib/fluid_cli/commands.rb +19 -0
  23. data/lib/fluid_cli/company_switcher.rb +69 -0
  24. data/lib/fluid_cli/context.rb +691 -0
  25. data/lib/fluid_cli/db.rb +114 -0
  26. data/lib/fluid_cli/entry_point.rb +10 -0
  27. data/lib/fluid_cli/environment.rb +32 -0
  28. data/lib/fluid_cli/file_system_listener.rb +29 -0
  29. data/lib/fluid_cli/form.rb +42 -0
  30. data/lib/fluid_cli/git.rb +319 -0
  31. data/lib/fluid_cli/http_request.rb +54 -0
  32. data/lib/fluid_cli/identity_auth/servlet.rb +39 -0
  33. data/lib/fluid_cli/identity_auth.rb +126 -0
  34. data/lib/fluid_cli/options.rb +38 -0
  35. data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +79 -0
  36. data/lib/fluid_cli/theme/dev_server/errors.rb +9 -0
  37. data/lib/fluid_cli/theme/dev_server/header_hash.rb +98 -0
  38. data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +39 -0
  39. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +27 -0
  40. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +28 -0
  41. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +43 -0
  42. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +16 -0
  43. data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +54 -0
  44. data/lib/fluid_cli/theme/dev_server/hot_reload.rb +75 -0
  45. data/lib/fluid_cli/theme/dev_server/local_assets.rb +92 -0
  46. data/lib/fluid_cli/theme/dev_server/proxy.rb +235 -0
  47. data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +82 -0
  48. data/lib/fluid_cli/theme/dev_server/reload_mode.rb +34 -0
  49. data/lib/fluid_cli/theme/dev_server/sse.rb +75 -0
  50. data/lib/fluid_cli/theme/dev_server/watcher.rb +57 -0
  51. data/lib/fluid_cli/theme/dev_server/web_server.rb +140 -0
  52. data/lib/fluid_cli/theme/dev_server.rb +289 -0
  53. data/lib/fluid_cli/theme/development_theme.rb +101 -0
  54. data/lib/fluid_cli/theme/file.rb +105 -0
  55. data/lib/fluid_cli/theme/forms/select.rb +33 -0
  56. data/lib/fluid_cli/theme/mime_type.rb +34 -0
  57. data/lib/fluid_cli/theme/presenters/theme_presenter.rb +49 -0
  58. data/lib/fluid_cli/theme/presenters/themes_presenter.rb +31 -0
  59. data/lib/fluid_cli/theme/root.rb +62 -0
  60. data/lib/fluid_cli/theme/syncer/checksums.rb +66 -0
  61. data/lib/fluid_cli/theme/syncer/downloader.rb +54 -0
  62. data/lib/fluid_cli/theme/syncer/error_reporter.rb +45 -0
  63. data/lib/fluid_cli/theme/syncer/merger.rb +53 -0
  64. data/lib/fluid_cli/theme/syncer/operation.rb +58 -0
  65. data/lib/fluid_cli/theme/syncer/standard_reporter.rb +32 -0
  66. data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +90 -0
  67. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +41 -0
  68. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +37 -0
  69. data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +64 -0
  70. data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +29 -0
  71. data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +30 -0
  72. data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +49 -0
  73. data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +71 -0
  74. data/lib/fluid_cli/theme/syncer/uploader.rb +105 -0
  75. data/lib/fluid_cli/theme/syncer.rb +412 -0
  76. data/lib/fluid_cli/theme/theme.rb +186 -0
  77. data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +22 -0
  78. data/lib/fluid_cli/thread_pool/job.rb +35 -0
  79. data/lib/fluid_cli/thread_pool.rb +49 -0
  80. data/lib/fluid_cli/version.rb +3 -0
  81. data/lib/fluid_cli.rb +59 -0
  82. data/vendor/deps/base64/.document +5 -0
  83. data/vendor/deps/base64/.gitignore +9 -0
  84. data/vendor/deps/base64/BSDL +22 -0
  85. data/vendor/deps/base64/COPYING +56 -0
  86. data/vendor/deps/base64/Gemfile +9 -0
  87. data/vendor/deps/base64/LEGAL +60 -0
  88. data/vendor/deps/base64/README.md +48 -0
  89. data/vendor/deps/base64/Rakefile +31 -0
  90. data/vendor/deps/base64/base64.gemspec +28 -0
  91. data/vendor/deps/base64/bin/console +14 -0
  92. data/vendor/deps/base64/bin/setup +8 -0
  93. data/vendor/deps/base64/lib/base64.rb +382 -0
  94. data/vendor/deps/base64/sig/base64.rbs +358 -0
  95. data/vendor/deps/base64/test/base64/test_base64.rb +115 -0
  96. data/vendor/deps/base64/test_sig/test_base64.rb +44 -0
  97. data/vendor/deps/cli-kit/REVISION +1 -0
  98. data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +286 -0
  99. data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +215 -0
  100. data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +128 -0
  101. data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +125 -0
  102. data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +130 -0
  103. data/vendor/deps/cli-kit/lib/cli/kit/args.rb +16 -0
  104. data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +30 -0
  105. data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +268 -0
  106. data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +150 -0
  107. data/vendor/deps/cli-kit/lib/cli/kit/config.rb +137 -0
  108. data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +28 -0
  109. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +166 -0
  110. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +92 -0
  111. data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +91 -0
  112. data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +92 -0
  113. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +94 -0
  114. data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +248 -0
  115. data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +55 -0
  116. data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +66 -0
  117. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +260 -0
  118. data/vendor/deps/cli-kit/lib/cli/kit/support.rb +11 -0
  119. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +290 -0
  120. data/vendor/deps/cli-kit/lib/cli/kit/util.rb +118 -0
  121. data/vendor/deps/cli-kit/lib/cli/kit/version.rb +7 -0
  122. data/vendor/deps/cli-kit/lib/cli/kit.rb +139 -0
  123. data/vendor/deps/cli-ui/REVISION +1 -0
  124. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +218 -0
  125. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +101 -0
  126. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +219 -0
  127. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +67 -0
  128. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +179 -0
  129. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +152 -0
  130. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +127 -0
  131. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +286 -0
  132. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +92 -0
  133. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
  134. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +64 -0
  135. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +132 -0
  136. data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +209 -0
  137. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +583 -0
  138. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +36 -0
  139. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +381 -0
  140. data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +48 -0
  141. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +602 -0
  142. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +79 -0
  143. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +399 -0
  144. data/vendor/deps/cli-ui/lib/cli/ui/table.rb +83 -0
  145. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +55 -0
  146. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +106 -0
  147. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +8 -0
  148. data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +46 -0
  149. data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +79 -0
  150. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +89 -0
  151. data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +142 -0
  152. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +61 -0
  153. data/vendor/deps/cli-ui/lib/cli/ui.rb +359 -0
  154. data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +78 -0
  155. data/vendor/deps/debug/CONTRIBUTING.md +573 -0
  156. data/vendor/deps/debug/Gemfile +10 -0
  157. data/vendor/deps/debug/LICENSE.txt +22 -0
  158. data/vendor/deps/debug/README.md +996 -0
  159. data/vendor/deps/debug/Rakefile +57 -0
  160. data/vendor/deps/debug/TODO.md +23 -0
  161. data/vendor/deps/debug/debug.gemspec +33 -0
  162. data/vendor/deps/debug/exe/rdbg +53 -0
  163. data/vendor/deps/debug/ext/debug/Makefile +273 -0
  164. data/vendor/deps/debug/ext/debug/debug.c +228 -0
  165. data/vendor/deps/debug/ext/debug/debug_version.h +1 -0
  166. data/vendor/deps/debug/ext/debug/extconf.rb +27 -0
  167. data/vendor/deps/debug/ext/debug/iseq_collector.c +93 -0
  168. data/vendor/deps/debug/lib/debug/abbrev_command.rb +77 -0
  169. data/vendor/deps/debug/lib/debug/breakpoint.rb +556 -0
  170. data/vendor/deps/debug/lib/debug/client.rb +263 -0
  171. data/vendor/deps/debug/lib/debug/color.rb +123 -0
  172. data/vendor/deps/debug/lib/debug/config.rb +592 -0
  173. data/vendor/deps/debug/lib/debug/console.rb +224 -0
  174. data/vendor/deps/debug/lib/debug/dap_custom/traceInspector.rb +336 -0
  175. data/vendor/deps/debug/lib/debug/debug.bundle +0 -0
  176. data/vendor/deps/debug/lib/debug/frame_info.rb +190 -0
  177. data/vendor/deps/debug/lib/debug/irb_integration.rb +37 -0
  178. data/vendor/deps/debug/lib/debug/local.rb +115 -0
  179. data/vendor/deps/debug/lib/debug/open.rb +13 -0
  180. data/vendor/deps/debug/lib/debug/open_nonstop.rb +15 -0
  181. data/vendor/deps/debug/lib/debug/prelude.rb +50 -0
  182. data/vendor/deps/debug/lib/debug/server.rb +534 -0
  183. data/vendor/deps/debug/lib/debug/server_cdp.rb +1348 -0
  184. data/vendor/deps/debug/lib/debug/server_dap.rb +1108 -0
  185. data/vendor/deps/debug/lib/debug/session.rb +2667 -0
  186. data/vendor/deps/debug/lib/debug/source_repository.rb +150 -0
  187. data/vendor/deps/debug/lib/debug/start.rb +5 -0
  188. data/vendor/deps/debug/lib/debug/thread_client.rb +1457 -0
  189. data/vendor/deps/debug/lib/debug/tracer.rb +241 -0
  190. data/vendor/deps/debug/lib/debug/version.rb +5 -0
  191. data/vendor/deps/debug/lib/debug.rb +9 -0
  192. data/vendor/deps/debug/misc/README.md.erb +660 -0
  193. data/vendor/deps/listen/.github/release-drafter.yml +17 -0
  194. data/vendor/deps/listen/.github/workflows/development.yml +67 -0
  195. data/vendor/deps/listen/.github/workflows/push.yml +12 -0
  196. data/vendor/deps/listen/.gitignore +28 -0
  197. data/vendor/deps/listen/.rspec +3 -0
  198. data/vendor/deps/listen/.rubocop.yml +283 -0
  199. data/vendor/deps/listen/.yardopts +11 -0
  200. data/vendor/deps/listen/CHANGELOG.md +1 -0
  201. data/vendor/deps/listen/CONTRIBUTING.md +45 -0
  202. data/vendor/deps/listen/Gemfile +33 -0
  203. data/vendor/deps/listen/Guardfile +26 -0
  204. data/vendor/deps/listen/LICENSE.txt +22 -0
  205. data/vendor/deps/listen/README.md +490 -0
  206. data/vendor/deps/listen/Rakefile +154 -0
  207. data/vendor/deps/listen/bin/listen +11 -0
  208. data/vendor/deps/listen/lib/listen/adapter/base.rb +129 -0
  209. data/vendor/deps/listen/lib/listen/adapter/bsd.rb +104 -0
  210. data/vendor/deps/listen/lib/listen/adapter/config.rb +31 -0
  211. data/vendor/deps/listen/lib/listen/adapter/darwin.rb +77 -0
  212. data/vendor/deps/listen/lib/listen/adapter/linux.rb +108 -0
  213. data/vendor/deps/listen/lib/listen/adapter/polling.rb +40 -0
  214. data/vendor/deps/listen/lib/listen/adapter/windows.rb +96 -0
  215. data/vendor/deps/listen/lib/listen/adapter.rb +43 -0
  216. data/vendor/deps/listen/lib/listen/backend.rb +40 -0
  217. data/vendor/deps/listen/lib/listen/change.rb +69 -0
  218. data/vendor/deps/listen/lib/listen/cli.rb +65 -0
  219. data/vendor/deps/listen/lib/listen/directory.rb +93 -0
  220. data/vendor/deps/listen/lib/listen/error.rb +11 -0
  221. data/vendor/deps/listen/lib/listen/event/config.rb +39 -0
  222. data/vendor/deps/listen/lib/listen/event/loop.rb +92 -0
  223. data/vendor/deps/listen/lib/listen/event/processor.rb +128 -0
  224. data/vendor/deps/listen/lib/listen/event/queue.rb +52 -0
  225. data/vendor/deps/listen/lib/listen/file.rb +95 -0
  226. data/vendor/deps/listen/lib/listen/fsm.rb +131 -0
  227. data/vendor/deps/listen/lib/listen/listener/config.rb +41 -0
  228. data/vendor/deps/listen/lib/listen/listener.rb +136 -0
  229. data/vendor/deps/listen/lib/listen/logger.rb +65 -0
  230. data/vendor/deps/listen/lib/listen/monotonic_time.rb +27 -0
  231. data/vendor/deps/listen/lib/listen/options.rb +24 -0
  232. data/vendor/deps/listen/lib/listen/queue_optimizer.rb +129 -0
  233. data/vendor/deps/listen/lib/listen/record/entry.rb +66 -0
  234. data/vendor/deps/listen/lib/listen/record/symlink_detector.rb +47 -0
  235. data/vendor/deps/listen/lib/listen/record.rb +122 -0
  236. data/vendor/deps/listen/lib/listen/silencer/controller.rb +50 -0
  237. data/vendor/deps/listen/lib/listen/silencer.rb +106 -0
  238. data/vendor/deps/listen/lib/listen/thread.rb +54 -0
  239. data/vendor/deps/listen/lib/listen/version.rb +5 -0
  240. data/vendor/deps/listen/lib/listen.rb +47 -0
  241. data/vendor/deps/listen/listen.gemspec +40 -0
  242. data/vendor/deps/listen/spec/acceptance/listen_spec.rb +320 -0
  243. data/vendor/deps/listen/spec/lib/listen/adapter/base_spec.rb +101 -0
  244. data/vendor/deps/listen/spec/lib/listen/adapter/bsd_spec.rb +13 -0
  245. data/vendor/deps/listen/spec/lib/listen/adapter/config_spec.rb +122 -0
  246. data/vendor/deps/listen/spec/lib/listen/adapter/darwin_spec.rb +82 -0
  247. data/vendor/deps/listen/spec/lib/listen/adapter/linux_spec.rb +199 -0
  248. data/vendor/deps/listen/spec/lib/listen/adapter/polling_spec.rb +83 -0
  249. data/vendor/deps/listen/spec/lib/listen/adapter/windows_spec.rb +13 -0
  250. data/vendor/deps/listen/spec/lib/listen/adapter_spec.rb +69 -0
  251. data/vendor/deps/listen/spec/lib/listen/backend_spec.rb +82 -0
  252. data/vendor/deps/listen/spec/lib/listen/change_spec.rb +102 -0
  253. data/vendor/deps/listen/spec/lib/listen/cli_spec.rb +116 -0
  254. data/vendor/deps/listen/spec/lib/listen/directory_spec.rb +284 -0
  255. data/vendor/deps/listen/spec/lib/listen/event/config_spec.rb +33 -0
  256. data/vendor/deps/listen/spec/lib/listen/event/loop_spec.rb +118 -0
  257. data/vendor/deps/listen/spec/lib/listen/event/processor_spec.rb +250 -0
  258. data/vendor/deps/listen/spec/lib/listen/event/queue_spec.rb +118 -0
  259. data/vendor/deps/listen/spec/lib/listen/file_spec.rb +254 -0
  260. data/vendor/deps/listen/spec/lib/listen/fsm_spec.rb +147 -0
  261. data/vendor/deps/listen/spec/lib/listen/listener/config_spec.rb +29 -0
  262. data/vendor/deps/listen/spec/lib/listen/listener_spec.rb +321 -0
  263. data/vendor/deps/listen/spec/lib/listen/logger_spec.rb +212 -0
  264. data/vendor/deps/listen/spec/lib/listen/monotonic_time_spec.rb +58 -0
  265. data/vendor/deps/listen/spec/lib/listen/queue_optimizer_spec.rb +111 -0
  266. data/vendor/deps/listen/spec/lib/listen/record_spec.rb +424 -0
  267. data/vendor/deps/listen/spec/lib/listen/silencer/controller_spec.rb +97 -0
  268. data/vendor/deps/listen/spec/lib/listen/silencer_spec.rb +109 -0
  269. data/vendor/deps/listen/spec/lib/listen/thread_spec.rb +133 -0
  270. data/vendor/deps/listen/spec/lib/listen_spec.rb +25 -0
  271. data/vendor/deps/listen/spec/spec_helper.rb +49 -0
  272. data/vendor/deps/listen/spec/support/acceptance_helper.rb +260 -0
  273. data/vendor/deps/listen/spec/support/fixtures_helper.rb +32 -0
  274. data/vendor/deps/listen/spec/support/platform_helper.rb +17 -0
  275. data/vendor/deps/observer/.github/dependabot.yml +6 -0
  276. data/vendor/deps/observer/.github/workflows/test.yml +33 -0
  277. data/vendor/deps/observer/.gitignore +8 -0
  278. data/vendor/deps/observer/BSDL +22 -0
  279. data/vendor/deps/observer/COPYING +56 -0
  280. data/vendor/deps/observer/Gemfile +9 -0
  281. data/vendor/deps/observer/README.md +139 -0
  282. data/vendor/deps/observer/Rakefile +10 -0
  283. data/vendor/deps/observer/bin/console +14 -0
  284. data/vendor/deps/observer/bin/setup +8 -0
  285. data/vendor/deps/observer/lib/observer.rb +229 -0
  286. data/vendor/deps/observer/observer.gemspec +32 -0
  287. data/vendor/deps/observer/test/test_observer.rb +66 -0
  288. data/vendor/deps/webrick/.gitignore +9 -0
  289. data/vendor/deps/webrick/Gemfile +3 -0
  290. data/vendor/deps/webrick/LICENSE.txt +22 -0
  291. data/vendor/deps/webrick/README.md +61 -0
  292. data/vendor/deps/webrick/Rakefile +10 -0
  293. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  294. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  295. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  296. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  297. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  298. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  299. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  300. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  301. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  302. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  303. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  304. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  305. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  306. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  307. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  308. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  309. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  310. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  311. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  312. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  313. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  314. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  315. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  316. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  317. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  318. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  319. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  320. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  321. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  322. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  323. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  324. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  325. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  326. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  327. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  328. data/vendor/deps/webrick/webrick.gemspec +74 -0
  329. metadata +412 -0
@@ -0,0 +1,286 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'cli/ui'
5
+ require 'cli/ui/frame/frame_stack'
6
+ require 'cli/ui/frame/frame_style'
7
+
8
+ module CLI
9
+ module UI
10
+ module Frame
11
+ class UnnestedFrameException < StandardError; end
12
+ DEFAULT_FRAME_COLOR = CLI::UI.resolve_color(:cyan)
13
+
14
+ class << self
15
+ #: -> FrameStyle
16
+ def frame_style
17
+ @frame_style ||= FrameStyle::Box
18
+ end
19
+
20
+ # Set the default frame style.
21
+ #
22
+ # Raises ArgumentError if +frame_style+ is not valid
23
+ #
24
+ # ==== Attributes
25
+ #
26
+ # * +symbol+ or +FrameStyle+ - the default frame style to use for frames
27
+ #
28
+ #: (frame_stylable frame_style) -> void
29
+ def frame_style=(frame_style)
30
+ @frame_style = CLI::UI.resolve_style(frame_style)
31
+ end
32
+
33
+ # Opens a new frame. Can be nested
34
+ # Can be invoked in two ways: block and blockless
35
+ # * In block form, the frame is closed automatically when the block returns
36
+ # * In blockless form, caller MUST call +Frame.close+ when the frame is logically done
37
+ # * Blockless form is strongly discouraged in cases where block form can be made to work
38
+ #
39
+ # https://user-images.githubusercontent.com/3074765/33799861-cb5dcb5c-dd01-11e7-977e-6fad38cee08c.png
40
+ #
41
+ # The return value of the block determines if the block is a "success" or a "failure"
42
+ #
43
+ # ==== Attributes
44
+ #
45
+ # * +text+ - (required) the text/title to output in the frame
46
+ #
47
+ # ==== Options
48
+ #
49
+ # * +:color+ - The color of the frame. Defaults to +DEFAULT_FRAME_COLOR+
50
+ # * +:failure_text+ - If the block failed, what do we output? Defaults to nil
51
+ # * +:success_text+ - If the block succeeds, what do we output? Defaults to nil
52
+ # * +:timing+ - How long did the frame content take? Invalid for blockless. Defaults to true for the block form
53
+ # * +frame_style+ - The frame style to use for this frame
54
+ # * +:to+ - Target stream, like $stdout or $stderr. Can be anything with print and puts methods,
55
+ # or under Sorbet, IO or StringIO. Defaults to $stdout.
56
+ #
57
+ # ==== Example
58
+ #
59
+ # ===== Block Form (Assumes +CLI::UI::StdoutRouter.enable+ has been called)
60
+ #
61
+ # CLI::UI::Frame.open('Open') { puts 'hi' }
62
+ #
63
+ # Default Output:
64
+ # ┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
65
+ # ┃ hi
66
+ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ (0.0s) ━━
67
+ #
68
+ # ===== Blockless Form
69
+ #
70
+ # CLI::UI::Frame.open('Open')
71
+ #
72
+ # Default Output:
73
+ # ┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
74
+ #
75
+ #
76
+ #: [T] (String text, ?color: colorable, ?failure_text: String?, ?success_text: String?, ?timing: (Numeric | bool), ?frame_style: frame_stylable, ?to: io_like) ?{ -> T } -> T?
77
+ def open(
78
+ text,
79
+ color: DEFAULT_FRAME_COLOR,
80
+ failure_text: nil,
81
+ success_text: nil,
82
+ timing: block_given?,
83
+ frame_style: self.frame_style,
84
+ to: $stdout,
85
+ &block
86
+ )
87
+ frame_style = CLI::UI.resolve_style(frame_style)
88
+ color = CLI::UI.resolve_color(color)
89
+
90
+ unless block_given?
91
+ if failure_text
92
+ raise ArgumentError, 'failure_text is not compatible with blockless invocation'
93
+ elsif success_text
94
+ raise ArgumentError, 'success_text is not compatible with blockless invocation'
95
+ elsif timing
96
+ raise ArgumentError, 'timing is not compatible with blockless invocation'
97
+ end
98
+ end
99
+
100
+ t_start = Time.now
101
+ CLI::UI.raw do
102
+ to.print(prefix.chop)
103
+ to.puts(frame_style.start(text, color: color))
104
+ end
105
+ FrameStack.push(color: color, style: frame_style)
106
+
107
+ return unless block_given?
108
+
109
+ closed = false
110
+ begin
111
+ success = false #: untyped
112
+ success = yield
113
+ rescue
114
+ closed = true
115
+ t_diff = elapsed(t_start, timing)
116
+ close(failure_text, color: :red, elapsed: t_diff, to: to)
117
+ raise
118
+ else
119
+ success
120
+ ensure
121
+ unless closed
122
+ t_diff = elapsed(t_start, timing)
123
+ success_bool = success #: as untyped
124
+ if success_bool != false
125
+ close(success_text, color: color, elapsed: t_diff, to: to)
126
+ else
127
+ close(failure_text, color: :red, elapsed: t_diff, to: to)
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ # Adds a divider in a frame
134
+ # Used to separate information within a single frame
135
+ #
136
+ # ==== Attributes
137
+ #
138
+ # * +text+ - (required) the text/title to output in the frame
139
+ #
140
+ # ==== Options
141
+ #
142
+ # * +:color+ - The color of the frame. Defaults to +DEFAULT_FRAME_COLOR+
143
+ # * +frame_style+ - The frame style to use for this frame
144
+ # * +:to+ - Target stream, like $stdout or $stderr. Can be anything with print and puts methods,
145
+ # or under Sorbet, IO or StringIO. Defaults to $stdout.
146
+ #
147
+ # ==== Example
148
+ #
149
+ # CLI::UI::Frame.open('Open') { CLI::UI::Frame.divider('Divider') }
150
+ #
151
+ # Default Output:
152
+ # ┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
153
+ # ┣━━ Divider ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
154
+ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
155
+ #
156
+ # ==== Raises
157
+ #
158
+ # MUST be inside an open frame or it raises a +UnnestedFrameException+
159
+ #
160
+ #: (String? text, ?color: colorable?, ?frame_style: frame_stylable?, ?to: io_like) -> void
161
+ def divider(text, color: nil, frame_style: nil, to: $stdout)
162
+ fs_item = FrameStack.pop
163
+ raise UnnestedFrameException, 'No frame nesting to unnest' unless fs_item
164
+
165
+ divider_color = CLI::UI.resolve_color(color || fs_item.color)
166
+ frame_style = CLI::UI.resolve_style(frame_style || fs_item.frame_style)
167
+
168
+ CLI::UI.raw do
169
+ to.print(prefix.chop)
170
+ to.puts(frame_style.divider(text.to_s, color: divider_color))
171
+ end
172
+
173
+ FrameStack.push(fs_item)
174
+ end
175
+
176
+ # Closes a frame
177
+ # Automatically called for a block-form +open+
178
+ #
179
+ # ==== Attributes
180
+ #
181
+ # * +text+ - (required) the text/title to output in the frame
182
+ #
183
+ # ==== Options
184
+ #
185
+ # * +:color+ - The color of the frame. Defaults to nil
186
+ # * +:elapsed+ - How long did the frame take? Defaults to nil
187
+ # * +frame_style+ - The frame style to use for this frame. Defaults to nil
188
+ # * +:to+ - Target stream, like $stdout or $stderr. Can be anything with print and puts methods,
189
+ # or under Sorbet, IO or StringIO. Defaults to $stdout.
190
+ #
191
+ # ==== Example
192
+ #
193
+ # CLI::UI::Frame.close('Close')
194
+ #
195
+ # Default Output:
196
+ # ┗━━ Close ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
197
+ #
198
+ # ==== Raises
199
+ #
200
+ # MUST be inside an open frame or it raises a +UnnestedFrameException+
201
+ #
202
+ #: (String? text, ?color: colorable?, ?elapsed: Numeric?, ?frame_style: frame_stylable?, ?to: io_like) -> void
203
+ def close(text, color: nil, elapsed: nil, frame_style: nil, to: $stdout)
204
+ fs_item = FrameStack.pop
205
+ raise UnnestedFrameException, 'No frame nesting to unnest' unless fs_item
206
+
207
+ close_color = CLI::UI.resolve_color(color || fs_item.color)
208
+ frame_style = CLI::UI.resolve_style(frame_style || fs_item.frame_style)
209
+ elapsed_string = elapsed ? "(#{elapsed.round(2)}s)" : nil
210
+
211
+ CLI::UI.raw do
212
+ to.print(prefix.chop)
213
+ to.puts(frame_style.close(text.to_s, color: close_color, right_text: elapsed_string))
214
+ end
215
+ end
216
+
217
+ # Determines the prefix of a frame entry taking multi-nested frames into account
218
+ #
219
+ # ==== Options
220
+ #
221
+ # * +:color+ - The color of the prefix. Defaults to +Thread.current[:cliui_frame_color_override]+
222
+ #
223
+ #: (?color: colorable?) -> String
224
+ def prefix(color: Thread.current[:cliui_frame_color_override])
225
+ (+'').tap do |output|
226
+ items = FrameStack.items
227
+
228
+ items[0..-2].to_a.each do |item|
229
+ output << item.color.code if CLI::UI.enable_color?
230
+ output << item.frame_style.prefix
231
+ output << CLI::UI::Color::RESET.code if CLI::UI.enable_color?
232
+ end
233
+
234
+ if (item = items.last)
235
+ final_color = color || item.color
236
+ output << CLI::UI.resolve_color(final_color).code if CLI::UI.enable_color?
237
+ output << item.frame_style.prefix
238
+ output << CLI::UI::Color::RESET.code if CLI::UI.enable_color?
239
+ output << ' '
240
+ end
241
+ end
242
+ end
243
+
244
+ # The width of a prefix given the number of Frames in the stack
245
+ #: -> Integer
246
+ def prefix_width
247
+ w = FrameStack.items.reduce(0) do |width, item|
248
+ width + item.frame_style.prefix_width
249
+ end
250
+
251
+ w.zero? ? w : w + 1
252
+ end
253
+
254
+ # Override a color for a given thread.
255
+ #
256
+ # ==== Attributes
257
+ #
258
+ # * +color+ - The color to override to
259
+ #
260
+ #: [T] (colorable color) { -> T } -> T
261
+ def with_frame_color_override(color, &block)
262
+ prev = Thread.current[:cliui_frame_color_override]
263
+ Thread.current[:cliui_frame_color_override] = color
264
+ yield
265
+ ensure
266
+ Thread.current[:cliui_frame_color_override] = prev
267
+ end
268
+
269
+ private
270
+
271
+ # If timing is:
272
+ # Numeric: return it
273
+ # false: return nil
274
+ # true: defaults to Time.new
275
+ #: (Time start, (Numeric | bool) timing) -> Numeric?
276
+ def elapsed(start, timing)
277
+ return timing if timing.is_a?(Numeric)
278
+ return if timing.is_a?(FalseClass)
279
+
280
+ timing = Time.new
281
+ timing - start
282
+ end
283
+ end
284
+ end
285
+ end
286
+ end
@@ -0,0 +1,92 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'cli/ui'
5
+
6
+ module CLI
7
+ module UI
8
+ class Glyph
9
+ class InvalidGlyphHandle < ArgumentError
10
+ #: (String handle) -> void
11
+ def initialize(handle)
12
+ super
13
+ @handle = handle
14
+ end
15
+
16
+ #: -> String
17
+ def message
18
+ keys = Glyph.available.join(',')
19
+ "invalid glyph handle: #{@handle} " \
20
+ "-- must be one of CLI::UI::Glyph.available (#{keys})"
21
+ end
22
+ end
23
+
24
+ #: String
25
+ attr_reader :handle, :to_s, :fmt, :char
26
+
27
+ #: (Integer | Array[Integer])
28
+ attr_reader :codepoint
29
+
30
+ #: Color
31
+ attr_reader :color
32
+
33
+ # Creates a new glyph
34
+ #
35
+ # ==== Attributes
36
+ #
37
+ # * +handle+ - The handle in the +MAP+ constant
38
+ # * +codepoint+ - The codepoint used to create the glyph (e.g. +0x2717+ for a ballot X)
39
+ # * +plain+ - A fallback plain string to be used in case glyphs are disabled
40
+ # * +color+ - What color to output the glyph. Check +CLI::UI::Color+ for options.
41
+ #
42
+ #: (String handle, (Integer | Array[Integer]) codepoint, String plain, Color color) -> void
43
+ def initialize(handle, codepoint, plain, color)
44
+ @handle = handle
45
+ @codepoint = codepoint
46
+ @color = color
47
+ @char = CLI::UI::OS.current.use_emoji? ? Array(codepoint).pack('U*') : plain
48
+ @to_s = color.code + @char + Color::RESET.code
49
+ @fmt = "{{#{color.name}:#{@char}}}"
50
+
51
+ MAP[handle] = self
52
+ end
53
+
54
+ # Mapping of glyphs to terminal output
55
+ MAP = {}
56
+ STAR = new('*', 0x2b51, '*', Color::YELLOW) # YELLOW SMALL STAR (⭑)
57
+ INFO = new('i', 0x1d4be, 'i', Color::BLUE) # BLUE MATHEMATICAL SCRIPT SMALL i (𝒾)
58
+ QUESTION = new('?', 0x003f, '?', Color::BLUE) # BLUE QUESTION MARK (?)
59
+ CHECK = new('v', 0x2713, '√', Color::GREEN) # GREEN CHECK MARK (✓)
60
+ X = new('x', 0x2717, 'X', Color::RED) # RED BALLOT X (✗)
61
+ BUG = new('b', 0x1f41b, '!', Color::WHITE) # Bug emoji (🐛)
62
+ CHEVRON = new('>', 0xbb, '»', Color::YELLOW) # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (»)
63
+ HOURGLASS = new('H', 0x29d6, 'H', Color::ORANGE) # HOURGLASS (⧖)
64
+ WARNING = new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW) # WARNING SIGN + VARIATION SELECTOR 16 (⚠️ )
65
+
66
+ class << self
67
+ # Looks up a glyph by name
68
+ #
69
+ # ==== Raises
70
+ # Raises a InvalidGlyphHandle if the glyph is not available
71
+ # You likely need to create it with +.new+ or you made a typo
72
+ #
73
+ # ==== Returns
74
+ # Returns a terminal output-capable string
75
+ #
76
+ #: (String name) -> Glyph
77
+ def lookup(name)
78
+ MAP.fetch(name.to_s)
79
+ rescue KeyError
80
+ raise InvalidGlyphHandle, name
81
+ end
82
+
83
+ # All available glyphs by name
84
+ #
85
+ #: -> Array[String]
86
+ def available
87
+ MAP.keys
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,63 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'rbconfig'
5
+
6
+ module CLI
7
+ module UI
8
+ class OS
9
+ #: (?emoji: bool, ?color_prompt: bool, ?arrow_keys: bool, ?shift_cursor: bool) -> void
10
+ def initialize(emoji: true, color_prompt: true, arrow_keys: true, shift_cursor: false)
11
+ @emoji = emoji
12
+ @color_prompt = color_prompt
13
+ @arrow_keys = arrow_keys
14
+ @shift_cursor = shift_cursor
15
+ end
16
+
17
+ #: -> bool
18
+ def use_emoji?
19
+ @emoji
20
+ end
21
+
22
+ #: -> bool
23
+ def use_color_prompt?
24
+ @color_prompt
25
+ end
26
+
27
+ #: -> bool
28
+ def suggest_arrow_keys?
29
+ @arrow_keys
30
+ end
31
+
32
+ #: -> bool
33
+ def shift_cursor_back_on_horizontal_absolute?
34
+ @shift_cursor
35
+ end
36
+
37
+ class << self
38
+ #: -> OS
39
+ def current
40
+ @current_os ||= case RbConfig::CONFIG['host_os']
41
+ when /darwin/
42
+ MAC
43
+ when /linux/
44
+ LINUX
45
+ when /freebsd/
46
+ FREEBSD
47
+ else
48
+ if RUBY_PLATFORM !~ /cygwin/ && ENV['OS'] == 'Windows_NT'
49
+ WINDOWS
50
+ else
51
+ raise "Could not determine OS from host_os #{RbConfig::CONFIG["host_os"]}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ MAC = OS.new
58
+ LINUX = OS.new
59
+ FREEBSD = OS.new
60
+ WINDOWS = OS.new(emoji: false, color_prompt: false, arrow_keys: false, shift_cursor: true)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'cli/ui'
5
+
6
+ module CLI
7
+ module UI
8
+ class Printer
9
+ class << self
10
+ # Print a message to a stream with common utilities.
11
+ # Allows overriding the color, encoding, and target stream.
12
+ # By default, it formats the string using CLI:UI and rescues common stream errors.
13
+ #
14
+ # ==== Attributes
15
+ #
16
+ # * +msg+ - (required) the string to output. Can be frozen.
17
+ #
18
+ # ==== Options
19
+ #
20
+ # * +:frame_color+ - Override the frame color. Defaults to nil.
21
+ # * +:to+ - Target stream, like $stdout or $stderr. Can be anything with a puts method. Defaults to $stdout.
22
+ # * +:encoding+ - Force the output to be in a certain encoding. Defaults to UTF-8.
23
+ # * +:format+ - Whether to format the string using CLI::UI.fmt. Defaults to true.
24
+ # * +:graceful+ - Whether to gracefully ignore common I/O errors. Defaults to true.
25
+ # * +:wrap+ - Whether to wrap text at word boundaries to terminal width. Defaults to true.
26
+ #
27
+ # ==== Returns
28
+ # Returns whether the message was successfully printed,
29
+ # which can be useful if +:graceful+ is set to true.
30
+ #
31
+ # ==== Example
32
+ #
33
+ # CLI::UI::Printer.puts('{{x}} Ouch', to: $stderr)
34
+ #
35
+ #: (String msg, ?frame_color: colorable?, ?to: io_like, ?encoding: Encoding?, ?format: bool, ?graceful: bool, ?wrap: bool) -> bool
36
+ def puts(
37
+ msg,
38
+ frame_color: nil,
39
+ to: $stdout,
40
+ encoding: Encoding::UTF_8,
41
+ format: true,
42
+ graceful: true,
43
+ wrap: true
44
+ )
45
+ msg = (+msg).force_encoding(encoding) if encoding
46
+ msg = CLI::UI.fmt(msg) if format
47
+ msg = CLI::UI.wrap(msg) if wrap
48
+
49
+ if frame_color
50
+ CLI::UI::Frame.with_frame_color_override(frame_color) { to.puts(msg) }
51
+ else
52
+ to.puts(msg)
53
+ end
54
+
55
+ true
56
+ rescue Errno::EIO, Errno::EPIPE, IOError => e
57
+ raise(e) unless graceful
58
+
59
+ false
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,132 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'cli/ui'
5
+
6
+ module CLI
7
+ module UI
8
+ class Progress
9
+ # A Cyan filled block
10
+ FILLED_BAR = "\e[46m"
11
+ # A bright white block
12
+ UNFILLED_BAR = "\e[1;47m"
13
+
14
+ class << self
15
+ # Add a progress bar to the terminal output
16
+ #
17
+ # https://user-images.githubusercontent.com/3074765/33799794-cc4c940e-dd00-11e7-9bdc-90f77ec9167c.gif
18
+ #
19
+ # ==== Example Usage:
20
+ #
21
+ # Set the percent to X
22
+ # CLI::UI::Progress.progress do |bar|
23
+ # bar.tick(set_percent: percent)
24
+ # end
25
+ #
26
+ # Increase the percent by 1 percent
27
+ # CLI::UI::Progress.progress do |bar|
28
+ # bar.tick
29
+ # end
30
+ #
31
+ # Increase the percent by X
32
+ # CLI::UI::Progress.progress do |bar|
33
+ # bar.tick(percent: 0.05)
34
+ # end
35
+ #
36
+ # Update the title
37
+ # CLI::UI::Progress.progress('Title') do |bar|
38
+ # bar.tick(percent: 0.05)
39
+ # bar.update_title('New title')
40
+ # end
41
+ #: [T] (?String? title, ?width: Integer) { (Progress bar) -> T } -> T
42
+ def progress(title = nil, width: Terminal.width, &block)
43
+ bar = nil #: Progress?
44
+ CLI::UI::ProgressReporter.with_progress(mode: :progress) do |reporter|
45
+ bar = Progress.new(title, width: width, reporter: reporter)
46
+ print(CLI::UI::ANSI.hide_cursor)
47
+ yield(bar)
48
+ end
49
+ ensure
50
+ puts(bar) if bar
51
+
52
+ CLI::UI.raw do
53
+ print(ANSI.show_cursor)
54
+ end
55
+ end
56
+ end
57
+
58
+ # Initialize a progress bar. Typically used in a +Progress.progress+ block
59
+ #
60
+ # ==== Options
61
+ #
62
+ # * +:title+ - The title of the progress bar
63
+ # * +:width+ - The width of the terminal
64
+ # * +:reporter+ - The progress reporter instance
65
+ #
66
+ #: (?String? title, ?width: Integer, ?reporter: ProgressReporter::Reporter?) -> void
67
+ def initialize(title = nil, width: Terminal.width, reporter: nil)
68
+ @percent_done = 0 #: Numeric
69
+ @title = title
70
+ @max_width = width
71
+ @reporter = reporter
72
+ end
73
+
74
+ # Set the progress of the bar. Typically used in a +Progress.progress+ block
75
+ #
76
+ # ==== Options
77
+ # One of the follow can be used, but not both together
78
+ #
79
+ # * +:percent+ - Increment progress by a specific percent amount
80
+ # * +:set_percent+ - Set progress to a specific percent
81
+ #
82
+ # *Note:* The +:percent+ and +:set_percent must be between 0.00 and 1.0
83
+ #
84
+ #: (?percent: Numeric?, ?set_percent: Numeric?) -> void
85
+ def tick(percent: nil, set_percent: nil)
86
+ raise ArgumentError, 'percent and set_percent cannot both be specified' if percent && set_percent
87
+
88
+ @percent_done += percent || 0.01
89
+ @percent_done = set_percent if set_percent
90
+ @percent_done = [@percent_done, 1.0].min # Make sure we can't go above 1.0
91
+
92
+ # Update terminal progress reporter with current percentage
93
+ @reporter&.set_progress((@percent_done * 100).floor)
94
+
95
+ print(self)
96
+
97
+ printed_lines = @title ? 2 : 1
98
+ print(CLI::UI::ANSI.previous_lines(printed_lines) + "\n")
99
+ end
100
+
101
+ # Update the progress bar title
102
+ #
103
+ # ==== Attributes
104
+ #
105
+ # * +new_title+ - title to change the progress bar to
106
+ #
107
+ #: (String new_title) -> void
108
+ def update_title(new_title)
109
+ @title = new_title
110
+ end
111
+
112
+ # Format the progress bar to be printed to terminal
113
+ #
114
+ #: -> String
115
+ def to_s
116
+ suffix = " #{(@percent_done * 100).floor}%".ljust(5)
117
+ workable_width = @max_width - Frame.prefix_width - suffix.size
118
+ filled = [(@percent_done * workable_width.to_f).ceil, 0].max
119
+ unfilled = [workable_width - filled, 0].max
120
+
121
+ title = CLI::UI.resolve_text(@title, truncate_to: @max_width - Frame.prefix_width) if @title
122
+ bar = CLI::UI.resolve_text([
123
+ FILLED_BAR + ' ' * filled,
124
+ UNFILLED_BAR + ' ' * unfilled,
125
+ CLI::UI::Color::RESET.code + suffix,
126
+ ].join)
127
+
128
+ [title, bar].compact.join("\n")
129
+ end
130
+ end
131
+ end
132
+ end