Module: CLI::UI
- Defined in:
- lib/cli/ui.rb,
lib/cli/ui/os.rb,
lib/cli/ui/ansi.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, OS, Prompt, Spinner, StdoutRouter, Terminal, Truncater, Widgets Classes: Color, Formatter, Glyph, Printer, Progress
Constant Summary collapse
- SpinGroup =
Convenience accessor to
CLI::UI::Spinner::SpinGroup
Spinner::SpinGroup
- VERSION =
"1.4.0"
Class Method Summary collapse
-
.ask(question, **kwargs) ⇒ Object
Convenience Method for
CLI::UI::Prompt.ask
. -
.confirm(question, **kwargs) ⇒ Object
Convenience Method for
CLI::UI::Prompt.confirm
. -
.enable_color=(bool) ⇒ Object
Turn colour output in Formatter on or off.
-
.enable_color? ⇒ Boolean
Check whether colour is enabled in Formatter output.
-
.fmt(input, enable_color: enable_color?) ) ⇒ Object
Convenience Method to format text using
CLI::UI::Formatter.format
CheckCLI::UI::Formatter::SGR_MAP
for available formatting options. -
.frame(*args, **kwargs, &block) ⇒ Object
Convenience Method for
CLI::UI::Frame.open
. -
.frame_style=(frame_style) ⇒ Object
Set the default frame style.
-
.glyph(handle) ⇒ Object
Glyph resolution using
CLI::UI::Glyph.lookup
Look at the method signature forGlyph.lookup
for more details. -
.log_output_to(path) ⇒ Object
Duplicate output to a file path.
-
.puts(msg, **kwargs) ⇒ Object
Convenience Method for
CLI::UI::Printer.puts
. -
.raw ⇒ Object
Disable all framing within a block.
-
.resolve_color(input) ⇒ Object
Color resolution using
CLI::UI::Color.lookup
Will lookup usingColor.lookup
unless it’s already a CLI::UI::Color (or nil). -
.resolve_style(input) ⇒ Object
Frame style resolution using
CLI::UI::Frame::FrameStyle.lookup
. -
.resolve_text(input, truncate_to: nil) ⇒ Object
Convenience Method to resolve text using
CLI::UI::Formatter.format
CheckCLI::UI::Formatter::SGR_MAP
for available formatting options. -
.spinner(*args, **kwargs, &block) ⇒ Object
Convenience Method for
CLI::UI::Spinner.spin
. -
.with_frame_color(color, &block) ⇒ Object
Convenience Method to override frame color using
CLI::UI::Frame.with_frame_color
.
Class Method Details
.ask(question, **kwargs) ⇒ Object
Convenience Method for CLI::UI::Prompt.ask
Attributes
-
question
- question to ask -
kwargs
- arguments forPrompt.ask
79 80 81 |
# File 'lib/cli/ui.rb', line 79 def self.ask(question, **kwargs) CLI::UI::Prompt.ask(question, **kwargs) end |
.confirm(question, **kwargs) ⇒ Object
Convenience Method for CLI::UI::Prompt.confirm
Attributes
-
question
- question to confirm
68 69 70 |
# File 'lib/cli/ui.rb', line 68 def self.confirm(question, **kwargs) CLI::UI::Prompt.confirm(question, **kwargs) end |
.enable_color=(bool) ⇒ Object
Turn colour output in Formatter on or off.
Attributes
-
bool
- true or false; enable or disable colour.
207 208 209 |
# File 'lib/cli/ui.rb', line 207 def self.enable_color=(bool) @enable_color = !!bool end |
.enable_color? ⇒ Boolean
Check whether colour is enabled in Formatter output. By default, colour is enabled when STDOUT is a TTY; that is, when output has not been redirected to another program or to a file.
197 198 199 |
# File 'lib/cli/ui.rb', line 197 def self.enable_color? @enable_color end |
.fmt(input, enable_color: enable_color?) ) ⇒ Object
Convenience Method to format text using CLI::UI::Formatter.format
Check CLI::UI::Formatter::SGR_MAP
for available formatting options
Attributes
-
input
- input to format
Options
-
enable_color
- should color be used? default to true unless output is redirected.
112 113 114 |
# File 'lib/cli/ui.rb', line 112 def self.fmt(input, enable_color: enable_color?) CLI::UI::Formatter.new(input).format(enable_color: enable_color) end |
.frame(*args, **kwargs, &block) ⇒ Object
Convenience Method for CLI::UI::Frame.open
Attributes
-
args
- arguments forFrame.open
-
block
- block forFrame.open
134 135 136 |
# File 'lib/cli/ui.rb', line 134 def self.frame(*args, **kwargs, &block) CLI::UI::Frame.open(*args, **kwargs, &block) end |
.frame_style=(frame_style) ⇒ Object
Set the default frame style. Convenience method for setting the default frame style with CLI::UI::Frame.frame_style=
Raises ArgumentError if frame_style
is not valid
Attributes
-
symbol
- the default frame style to use for frames
222 223 224 |
# File 'lib/cli/ui.rb', line 222 def self.frame_style=(frame_style) Frame.frame_style = frame_style.to_sym end |
.glyph(handle) ⇒ Object
Glyph resolution using CLI::UI::Glyph.lookup
Look at the method signature for Glyph.lookup
for more details
Attributes
-
handle
- handle of the glyph to resolve
27 28 29 |
# File 'lib/cli/ui.rb', line 27 def self.glyph(handle) CLI::UI::Glyph.lookup(handle) end |
.log_output_to(path) ⇒ Object
Duplicate output to a file path
Attributes
-
path
- path to duplicate output to
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/cli/ui.rb', line 166 def self.log_output_to(path) 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) file_descriptor.close CLI::UI::StdoutRouter.duplicate_output_to = nil end end |
.puts(msg, **kwargs) ⇒ Object
Convenience Method for CLI::UI::Printer.puts
Attributes
-
msg
- Message to print -
kwargs
- keyword arguments forPrinter.puts
123 124 125 |
# File 'lib/cli/ui.rb', line 123 def self.puts(msg, **kwargs) CLI::UI::Printer.puts(msg, **kwargs) end |
.raw ⇒ Object
Disable all framing within a block
Attributes
-
block
- block in which to disable frames
185 186 187 188 189 190 191 |
# File 'lib/cli/ui.rb', line 185 def self.raw 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
Color resolution using CLI::UI::Color.lookup
Will lookup using Color.lookup
unless it’s already a CLI::UI::Color (or nil)
Attributes
-
input
- color to resolve
38 39 40 41 42 43 44 45 |
# File 'lib/cli/ui.rb', line 38 def self.resolve_color(input) case input when CLI::UI::Color, nil input else CLI::UI::Color.lookup(input) end end |
.resolve_style(input) ⇒ Object
Frame style resolution using CLI::UI::Frame::FrameStyle.lookup
. Will lookup using FrameStyle.lookup
unless it’s already a CLI::UI::Frame::FrameStyle(or nil)
Attributes
-
input
- frame style to resolve
53 54 55 56 57 58 59 60 |
# File 'lib/cli/ui.rb', line 53 def self.resolve_style(input) case input when CLI::UI::Frame::FrameStyle, nil input else CLI::UI::Frame::FrameStyle.lookup(input) end end |
.resolve_text(input, truncate_to: nil) ⇒ Object
Convenience Method to resolve text using CLI::UI::Formatter.format
Check CLI::UI::Formatter::SGR_MAP
for available formatting options
Attributes
-
input
- input to format -
truncate_to
- number of characters to truncate the string to (or nil)
91 92 93 94 95 96 |
# File 'lib/cli/ui.rb', line 91 def self.resolve_text(input, truncate_to: nil) return input if input.nil? formatted = CLI::UI::Formatter.new(input).format return formatted unless truncate_to CLI::UI::Truncater.call(formatted, truncate_to) end |
.spinner(*args, **kwargs, &block) ⇒ Object
Convenience Method for CLI::UI::Spinner.spin
Attributes
-
args
- arguments forSpinner.open
-
block
- block forSpinner.open
145 146 147 |
# File 'lib/cli/ui.rb', line 145 def self.spinner(*args, **kwargs, &block) CLI::UI::Spinner.spin(*args, **kwargs, &block) end |
.with_frame_color(color, &block) ⇒ Object
Convenience Method to override frame color using CLI::UI::Frame.with_frame_color
Attributes
-
color
- color to override to -
block
- block forFrame.with_frame_color_override
156 157 158 |
# File 'lib/cli/ui.rb', line 156 def self.with_frame_color(color, &block) CLI::UI::Frame.with_frame_color_override(color, &block) end |