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 =
'2.2.3'

Class Method Summary collapse

Methods included from T::Sig

sig

Class Method Details

.any_key(prompt = 'Press any key to continue') ⇒ Object



99
100
101
# File 'lib/cli/ui.rb', line 99

def any_key(prompt = 'Press any key to continue')
  CLI::UI::Prompt.any_key(prompt)
end

.ask(question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, &options_proc) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cli/ui.rb', line 117

def ask(
  question,
  options: nil,
  default: nil,
  is_file: false,
  allow_empty: true,
  multiple: false,
  filter_ui: true,
  select_ui: true,
  &options_proc
)
  CLI::UI::Prompt.ask(
    question,
    options: options,
    default: default,
    is_file: is_file,
    allow_empty: allow_empty,
    multiple: multiple,
    filter_ui: filter_ui,
    select_ui: select_ui,
    &options_proc
  )
end

.confirm(question, default: true) ⇒ Object



88
89
90
# File 'lib/cli/ui.rb', line 88

def confirm(question, default: true)
  CLI::UI::Prompt.confirm(question, default: default)
end

.enable_color=(bool) ⇒ Object



348
349
350
# File 'lib/cli/ui.rb', line 348

def enable_color=(bool)
  @enable_color = !!bool
end

.enable_color?Boolean

Returns:

  • (Boolean)


337
338
339
# File 'lib/cli/ui.rb', line 337

def enable_color?
  @enable_color
end

.fmt(input, enable_color: enable_color?) ) ⇒ Object



172
173
174
# File 'lib/cli/ui.rb', line 172

def 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



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/cli/ui.rb', line 237

def 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



362
363
364
# File 'lib/cli/ui.rb', line 362

def frame_style=(frame_style)
  Frame.frame_style = frame_style
end

.glyph(handle) ⇒ Object



44
45
46
# File 'lib/cli/ui.rb', line 44

def glyph(handle)
  CLI::UI::Glyph.lookup(handle)
end


368
369
370
371
372
373
374
# File 'lib/cli/ui.rb', line 368

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

.log_output_to(path, &block) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/cli/ui.rb', line 299

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

.puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/cli/ui.rb', line 199

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

.raw(&block) ⇒ Object



324
325
326
327
328
329
330
# File 'lib/cli/ui.rb', line 324

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

.resolve_color(input) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/cli/ui.rb', line 56

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

.resolve_style(input) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/cli/ui.rb', line 72

def 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



150
151
152
153
154
155
# File 'lib/cli/ui.rb', line 150

def 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



268
269
270
# File 'lib/cli/ui.rb', line 268

def spinner(title, auto_debrief: true, &block)
  CLI::UI::Spinner.spin(title, auto_debrief: auto_debrief, &block)
end

.with_frame_color(color, &block) ⇒ Object



284
285
286
# File 'lib/cli/ui.rb', line 284

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

.wrap(input) ⇒ Object



177
178
179
# File 'lib/cli/ui.rb', line 177

def wrap(input)
  CLI::UI::Wrap.new(input).wrap
end