Module: CLI::UI

Defined in:
lib/cli/ui.rb,
lib/cli/ui/box.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/spinner.rb,
lib/cli/ui/version.rb,
lib/cli/ui/progress.rb,
lib/cli/ui/terminal.rb,
lib/cli/ui/formatter.rb,
lib/cli/ui/spinner/async.rb,
lib/cli/ui/stdout_router.rb,
lib/cli/ui/spinner/spin_group.rb,
lib/cli/ui/prompt/options_handler.rb,
lib/cli/ui/prompt/interactive_options.rb

Defined Under Namespace

Modules: ANSI, Box, Frame, Prompt, Spinner, StdoutRouter, Terminal Classes: Color, Formatter, Glyph, Progress

Constant Summary collapse

SpinGroup =

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

Spinner::SpinGroup
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.ask(question, **kwargs) ⇒ Object

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

Attributes

  • question - question to ask

  • kwargs - arugments for Prompt.ask



61
62
63
# File 'lib/cli/ui.rb', line 61

def self.ask(question, **kwargs)
  CLI::UI::Prompt.ask(question, **kwargs)
end

.confirm(question) ⇒ Object

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

Attributes

  • question - question to confirm



50
51
52
# File 'lib/cli/ui.rb', line 50

def self.confirm(question)
  CLI::UI::Prompt.confirm(question)
end

.fmt(input, enable_color: true) ⇒ Object

Conviencence 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



91
92
93
# File 'lib/cli/ui.rb', line 91

def self.fmt(input, enable_color: true)
  CLI::UI::Formatter.new(input).format(enable_color: enable_color)
end

.frame(*args, &block) ⇒ Object

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

Attributes

  • args - arguments for Frame.open

  • block - block for Frame.open



102
103
104
# File 'lib/cli/ui.rb', line 102

def self.frame(*args, &block)
  CLI::UI::Frame.open(*args, &block)
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



24
25
26
# File 'lib/cli/ui.rb', line 24

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



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/cli/ui.rb', line 134

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

.rawObject

Disable all framing within a block

Attributes

  • block - block in which to disable frames



153
154
155
156
157
158
159
# File 'lib/cli/ui.rb', line 153

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 if a symbol, otherwise we assume it is a valid color and return it

Attributes

  • input - color to resolve



35
36
37
38
39
40
41
42
# File 'lib/cli/ui.rb', line 35

def self.resolve_color(input)
  case input
  when Symbol
    CLI::UI::Color.lookup(input)
  else
    input
  end
end

.resolve_text(input) ⇒ Object

Conviencence Method to resolve text using CLI::UI::Formatter.format Check CLI::UI::Formatter::SGR_MAP for available formatting options

Attributes

  • input - input to format



72
73
74
75
# File 'lib/cli/ui.rb', line 72

def self.resolve_text(input)
  return input if input.nil?
  CLI::UI::Formatter.new(input).format
end

.spinner(*args, &block) ⇒ Object

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

Attributes

  • args - arguments for Spinner.open

  • block - block for Spinner.open



113
114
115
# File 'lib/cli/ui.rb', line 113

def self.spinner(*args, &block)
  CLI::UI::Spinner.spin(*args, &block)
end

.with_frame_color(color, &block) ⇒ Object

Conviencence 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



124
125
126
# File 'lib/cli/ui.rb', line 124

def self.with_frame_color(color, &block)
  CLI::UI::Frame.with_frame_color_override(color, &block)
end