Module: CLI::UI
- Extended by:
- T::Sig
- Defined in:
- lib/cli/ui.rb,
lib/cli/ui/os.rb,
lib/cli/ui/ansi.rb,
lib/cli/ui/wrap.rb,
lib/cli/ui/color.rb,
lib/cli/ui/frame.rb,
lib/cli/ui/glyph.rb,
lib/cli/ui/table.rb,
lib/cli/ui/prompt.rb,
lib/cli/ui/printer.rb,
lib/cli/ui/spinner.rb,
lib/cli/ui/version.rb,
lib/cli/ui/widgets.rb,
lib/cli/ui/progress.rb,
lib/cli/ui/terminal.rb,
lib/cli/ui/formatter.rb,
lib/cli/ui/truncater.rb,
lib/cli/ui/work_queue.rb,
lib/cli/ui/widgets/base.rb,
lib/cli/ui/spinner/async.rb,
lib/cli/ui/stdout_router.rb,
lib/cli/ui/widgets/status.rb,
lib/cli/ui/frame/frame_stack.rb,
lib/cli/ui/frame/frame_style.rb,
lib/cli/ui/spinner/spin_group.rb,
lib/cli/ui/frame/frame_style/box.rb,
lib/cli/ui/prompt/options_handler.rb,
lib/cli/ui/frame/frame_style/bracket.rb,
lib/cli/ui/prompt/interactive_options.rb more...
Defined Under Namespace
Modules: ANSI, Frame, Prompt, Spinner, StdoutRouter, Table, Terminal, Truncater, Widgets Classes: Color, Formatter, Glyph, OS, Printer, Progress, WorkQueue, Wrap
Constant Summary collapse
- SpinGroup =
Convenience accessor to
CLI::UI::Spinner::SpinGroup
Spinner::SpinGroup
- Colorable =
T.type_alias { T.any(Symbol, String, CLI::UI::Color) }
- FrameStylable =
T.type_alias { T.any(Symbol, String, CLI::UI::Frame::FrameStyle) }
- IOLike =
T.type_alias { T.any(IO, StringIO) }
- VERSION =
'2.3.1'
Class Method Summary collapse
- .any_key(prompt = 'Press any key to continue') ⇒ Object
- .ask(question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, &options_proc) ⇒ Object
- .confirm(question, default: true) ⇒ Object
- .enable_color=(bool) ⇒ Object
- .enable_color? ⇒ Boolean
- .enable_cursor=(bool) ⇒ Object
- .enable_cursor? ⇒ Boolean
- .fmt(input, enable_color: enable_color?) ) ⇒ Object
- .frame(text, color: Frame::DEFAULT_FRAME_COLOR, failure_text: nil, success_text: nil, timing: block_given?, , frame_style: Frame.frame_style, to: $stdout, &block) ⇒ Object
- .frame_style=(frame_style) ⇒ Object
- .glyph(handle) ⇒ Object
- .link(url, text, format: true, blue_underline: format) ⇒ Object
- .log_output_to(path, &block) ⇒ Object
- .puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true) ⇒ Object
- .raw(&block) ⇒ Object
- .resolve_color(input) ⇒ Object
- .resolve_style(input) ⇒ Object
- .resolve_text(input, truncate_to: nil, enable_color: enable_color?) ) ⇒ Object
- .spinner(title, auto_debrief: true, to: $stdout, &block) ⇒ Object
- .with_frame_color(color, &block) ⇒ Object
- .wrap(input) ⇒ Object
Methods included from T::Sig
Class Method Details
permalink .any_key(prompt = 'Press any key to continue') ⇒ Object
[View source]
101 102 103 |
# File 'lib/cli/ui.rb', line 101 def any_key(prompt = 'Press any key to continue') CLI::UI::Prompt.any_key(prompt) end |
permalink .ask(question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, &options_proc) ⇒ Object
[View source]
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cli/ui.rb', line 119 def ask( question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, & ) CLI::UI::Prompt.ask( question, options: , default: default, is_file: is_file, allow_empty: allow_empty, multiple: multiple, filter_ui: filter_ui, select_ui: select_ui, & ) end |
permalink .confirm(question, default: true) ⇒ Object
[View source]
90 91 92 |
# File 'lib/cli/ui.rb', line 90 def confirm(question, default: true) CLI::UI::Prompt.confirm(question, default: default) end |
permalink .enable_color=(bool) ⇒ Object
[View source]
358 359 360 |
# File 'lib/cli/ui.rb', line 358 def enable_color=(bool) @enable_color = !!bool end |
permalink .enable_color? ⇒ Boolean
347 348 349 |
# File 'lib/cli/ui.rb', line 347 def enable_color? @enable_color end |
permalink .enable_cursor=(bool) ⇒ Object
[View source]
378 379 380 |
# File 'lib/cli/ui.rb', line 378 def enable_cursor=(bool) @enable_cursor = !!bool end |
permalink .enable_cursor? ⇒ Boolean
367 368 369 |
# File 'lib/cli/ui.rb', line 367 def enable_cursor? @enable_cursor end |
permalink .fmt(input, enable_color: enable_color?) ) ⇒ Object
[View source]
175 176 177 |
# File 'lib/cli/ui.rb', line 175 def fmt(input, enable_color: enable_color?) CLI::UI::Formatter.new(input).format(enable_color: enable_color) end |
permalink .frame(text, color: Frame::DEFAULT_FRAME_COLOR, failure_text: nil, success_text: nil, timing: block_given?, , frame_style: Frame.frame_style, to: $stdout, &block) ⇒ Object
[View source]
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/cli/ui.rb', line 241 def frame( text, color: Frame::DEFAULT_FRAME_COLOR, failure_text: nil, success_text: nil, timing: block_given?, frame_style: Frame.frame_style, to: $stdout, &block ) CLI::UI::Frame.open( text, color: color, failure_text: failure_text, success_text: success_text, timing: timing, frame_style: frame_style, to: to, &block ) end |
permalink .frame_style=(frame_style) ⇒ Object
[View source]
392 393 394 |
# File 'lib/cli/ui.rb', line 392 def frame_style=(frame_style) Frame.frame_style = frame_style end |
permalink .glyph(handle) ⇒ Object
[View source]
46 47 48 |
# File 'lib/cli/ui.rb', line 46 def glyph(handle) CLI::UI::Glyph.lookup(handle) end |
permalink .link(url, text, format: true, blue_underline: format) ⇒ Object
[View source]
398 399 400 401 402 403 404 |
# File 'lib/cli/ui.rb', line 398 def link(url, text, format: true, blue_underline: format) raise 'cannot use blue_underline without format' if blue_underline && !format text = "{{blue:{{underline:#{text}}}}}" if blue_underline text = CLI::UI.fmt(text) if format "\x1b]8;;#{url}\x1b\\#{text}\x1b]8;;\x1b\\" end |
permalink .log_output_to(path, &block) ⇒ Object
[View source]
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/cli/ui.rb', line 309 def log_output_to(path, &block) if CLI::UI::StdoutRouter.duplicate_output_to raise 'multiple logs not allowed' end CLI::UI::StdoutRouter.duplicate_output_to = File.open(path, 'w') yield ensure if (file_descriptor = CLI::UI::StdoutRouter.duplicate_output_to) begin file_descriptor.close rescue IOError nil end CLI::UI::StdoutRouter.duplicate_output_to = nil end end |
permalink .puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true) ⇒ Object
[View source]
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/cli/ui.rb', line 202 def puts( msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true ) CLI::UI::Printer.puts( msg, frame_color: frame_color, to: to, encoding: encoding, format: format, graceful: graceful, wrap: wrap, ) end |
permalink .raw(&block) ⇒ Object
[View source]
334 335 336 337 338 339 340 |
# File 'lib/cli/ui.rb', line 334 def raw(&block) prev = Thread.current[:no_cliui_frame_inset] Thread.current[:no_cliui_frame_inset] = true yield ensure Thread.current[:no_cliui_frame_inset] = prev end |
permalink .resolve_color(input) ⇒ Object
[View source]
58 59 60 61 62 63 64 65 |
# File 'lib/cli/ui.rb', line 58 def resolve_color(input) case input when CLI::UI::Color input else CLI::UI::Color.lookup(input) end end |
permalink .resolve_style(input) ⇒ Object
[View source]
74 75 76 77 78 79 80 81 |
# File 'lib/cli/ui.rb', line 74 def resolve_style(input) case input when CLI::UI::Frame::FrameStyle input else CLI::UI::Frame::FrameStyle.lookup(input.to_s) end end |
permalink .resolve_text(input, truncate_to: nil, enable_color: enable_color?) ) ⇒ Object
[View source]
153 154 155 156 157 158 |
# File 'lib/cli/ui.rb', line 153 def resolve_text(input, truncate_to: nil, enable_color: enable_color?) formatted = CLI::UI::Formatter.new(input).format(enable_color: enable_color) return formatted unless truncate_to CLI::UI::Truncater.call(formatted, truncate_to) end |
permalink .spinner(title, auto_debrief: true, to: $stdout, &block) ⇒ Object
[View source]
278 279 280 |
# File 'lib/cli/ui.rb', line 278 def spinner(title, auto_debrief: true, to: $stdout, &block) CLI::UI::Spinner.spin(title, auto_debrief: auto_debrief, to: to, &block) end |
permalink .with_frame_color(color, &block) ⇒ Object
[View source]
294 295 296 |
# File 'lib/cli/ui.rb', line 294 def with_frame_color(color, &block) CLI::UI::Frame.with_frame_color_override(color, &block) end |