module CLI::UI

Constants

SpinGroup

Convenience accessor to CLI::UI::Spinner::SpinGroup

VERSION

Public Class Methods

ask(question, **kwargs) click to toggle source

Convenience Method for CLI::UI::Prompt.ask

Attributes

  • question - question to ask

  • kwargs - arguments for Prompt.ask

# File lib/cli/ui.rb, line 80
def self.ask(question, **kwargs)
  CLI::UI::Prompt.ask(question, **kwargs)
end
confirm(question, **kwargs) click to toggle source

Convenience Method for CLI::UI::Prompt.confirm

Attributes

  • question - question to confirm

# File lib/cli/ui.rb, line 69
def self.confirm(question, **kwargs)
  CLI::UI::Prompt.confirm(question, **kwargs)
end
enable_color=(bool) click to toggle source

Turn colour output in Formatter on or off.

Attributes

  • bool - true or false; enable or disable colour.

# File lib/cli/ui.rb, line 212
def self.enable_color=(bool)
  @enable_color = !!bool
end
enable_color?() click to toggle source

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.

# File lib/cli/ui.rb, line 202
def self.enable_color?
  @enable_color
end
fmt(input, enable_color: enable_color?) click to toggle source

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.

# File lib/cli/ui.rb, line 113
def self.fmt(input, enable_color: enable_color?)
  CLI::UI::Formatter.new(input).format(enable_color: enable_color)
end
frame(*args, **kwargs, &block) click to toggle source

Convenience Method for CLI::UI::Frame.open

Attributes

  • args - arguments for Frame.open

  • block - block for Frame.open

# File lib/cli/ui.rb, line 139
def self.frame(*args, **kwargs, &block)
  CLI::UI::Frame.open(*args, **kwargs, &block)
end
frame_style=(frame_style) click to toggle source

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

# File lib/cli/ui.rb, line 227
def self.frame_style=(frame_style)
  Frame.frame_style = frame_style.to_sym
end
glyph(handle) click to toggle source

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

# File lib/cli/ui.rb, line 28
def self.glyph(handle)
  CLI::UI::Glyph.lookup(handle)
end
log_output_to(path) { || ... } click to toggle source

Duplicate output to a file path

Attributes

  • path - path to duplicate output to

# File lib/cli/ui.rb, line 171
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) click to toggle source

Convenience Method for CLI::UI::Printer.puts

Attributes

  • msg - Message to print

  • kwargs - keyword arguments for Printer.puts

# File lib/cli/ui.rb, line 128
def self.puts(msg, **kwargs)
  CLI::UI::Printer.puts(msg, **kwargs)
end
raw() { || ... } click to toggle source

Disable all framing within a block

Attributes

  • block - block in which to disable frames

# File lib/cli/ui.rb, line 190
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) click to toggle source

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

# File lib/cli/ui.rb, line 39
def self.resolve_color(input)
  case input
  when CLI::UI::Color, nil
    input
  else
    CLI::UI::Color.lookup(input)
  end
end
resolve_style(input) click to toggle source

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

# File lib/cli/ui.rb, line 54
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) click to toggle source

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)

# File lib/cli/ui.rb, line 92
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) click to toggle source

Convenience Method for CLI::UI::Spinner.spin

Attributes

  • args - arguments for Spinner.open

  • block - block for Spinner.open

# File lib/cli/ui.rb, line 150
def self.spinner(*args, **kwargs, &block)
  CLI::UI::Spinner.spin(*args, **kwargs, &block)
end
with_frame_color(color, &block) click to toggle source

Convenience Method to override frame color using CLI::UI::Frame.with_frame_color

Attributes

  • color - color to override to

  • block - block for Frame.with_frame_color_override

# File lib/cli/ui.rb, line 161
def self.with_frame_color(color, &block)
  CLI::UI::Frame.with_frame_color_override(color, &block)
end
wrap(input) click to toggle source
# File lib/cli/ui.rb, line 117
def self.wrap(input)
  CLI::UI::Wrap.new(input).wrap
end