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/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/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
Defined Under Namespace
Modules: ANSI, Frame, Prompt, Spinner, StdoutRouter, Terminal, Truncater, Widgets Classes: Color, Formatter, Glyph, OS, Printer, Progress, 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 =
'1.5.1'
Class Method Summary collapse
- .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
- .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, &block) ⇒ Object
- .frame_style=(frame_style) ⇒ Object
- .glyph(handle) ⇒ 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) ⇒ Object
- .spinner(title, auto_debrief: true, &block) ⇒ Object
- .with_frame_color(color, &block) ⇒ Object
- .wrap(input) ⇒ Object
Methods included from T::Sig
Class Method Details
.ask(question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, &options_proc) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cli/ui.rb', line 103 def self.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 |
.confirm(question, default: true) ⇒ Object
85 86 87 |
# File 'lib/cli/ui.rb', line 85 def self.confirm(question, default: true) CLI::UI::Prompt.confirm(question, default: default) end |
.enable_color=(bool) ⇒ Object
334 335 336 |
# File 'lib/cli/ui.rb', line 334 def self.enable_color=(bool) @enable_color = !!bool end |
.enable_color? ⇒ Boolean
323 324 325 |
# File 'lib/cli/ui.rb', line 323 def self.enable_color? @enable_color end |
.fmt(input, enable_color: enable_color?) ) ⇒ Object
158 159 160 |
# File 'lib/cli/ui.rb', line 158 def self.fmt(input, enable_color: enable_color?) CLI::UI::Formatter.new(input).format(enable_color: enable_color) end |
.frame(text, color: Frame::DEFAULT_FRAME_COLOR, failure_text: nil, success_text: nil, timing: block_given?, , frame_style: Frame.frame_style, &block) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/cli/ui.rb', line 223 def self.frame( text, color: Frame::DEFAULT_FRAME_COLOR, failure_text: nil, success_text: nil, timing: block_given?, frame_style: Frame.frame_style, &block ) CLI::UI::Frame.open( text, color: color, failure_text: failure_text, success_text: success_text, timing: timing, frame_style: frame_style, &block ) end |
.frame_style=(frame_style) ⇒ Object
350 351 352 |
# File 'lib/cli/ui.rb', line 350 def self.frame_style=(frame_style) Frame.frame_style = frame_style end |
.glyph(handle) ⇒ Object
41 42 43 |
# File 'lib/cli/ui.rb', line 41 def self.glyph(handle) CLI::UI::Glyph.lookup(handle) end |
.log_output_to(path, &block) ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/cli/ui.rb', line 285 def self.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 |
.puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cli/ui.rb', line 185 def self.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 |
.raw(&block) ⇒ Object
310 311 312 313 314 315 316 |
# File 'lib/cli/ui.rb', line 310 def self.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 |
.resolve_color(input) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/cli/ui.rb', line 53 def self.resolve_color(input) case input when CLI::UI::Color input else CLI::UI::Color.lookup(input) end end |
.resolve_style(input) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/cli/ui.rb', line 69 def self.resolve_style(input) case input when CLI::UI::Frame::FrameStyle input else CLI::UI::Frame::FrameStyle.lookup(input.to_s) end end |
.resolve_text(input, truncate_to: nil) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/cli/ui.rb', line 136 def self.resolve_text(input, truncate_to: nil) formatted = CLI::UI::Formatter.new(input).format return formatted unless truncate_to CLI::UI::Truncater.call(formatted, truncate_to) end |
.spinner(title, auto_debrief: true, &block) ⇒ Object
254 255 256 |
# File 'lib/cli/ui.rb', line 254 def self.spinner(title, auto_debrief: true, &block) CLI::UI::Spinner.spin(title, auto_debrief: auto_debrief, &block) end |
.with_frame_color(color, &block) ⇒ Object
270 271 272 |
# File 'lib/cli/ui.rb', line 270 def self.with_frame_color(color, &block) CLI::UI::Frame.with_frame_color_override(color, &block) end |