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/table.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/work_queue.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, Table, Terminal, Truncater, Widgets
Classes: Color, Formatter, Glyph, OS, Printer, Progress, WorkQueue, 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
-
.any_key(prompt = 'Press any key to continue') ⇒ Object
-
.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
-
.enable_cursor=(bool) ⇒ Object
-
.enable_cursor? ⇒ 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, to: $stdout, &block) ⇒ Object
-
.frame_style=(frame_style) ⇒ Object
-
.glyph(handle) ⇒ Object
-
.link(url, text, format: true, blue_underline: format) ⇒ 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, enable_color: enable_color?) ) ⇒ Object
-
.spinner(title, auto_debrief: true, &block) ⇒ Object
-
.with_frame_color(color, &block) ⇒ Object
-
.wrap(input) ⇒ Object
Methods included from T::Sig
sig
Class Method Details
.any_key(prompt = 'Press any key to continue') ⇒ Object
101
102
103
|
# File 'lib/cli/ui.rb', line 101
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/cli/ui.rb', line 119
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
90
91
92
|
# File 'lib/cli/ui.rb', line 90
def confirm(question, default: true)
CLI::UI::Prompt.confirm(question, default: default)
end
|
.enable_color=(bool) ⇒ Object
354
355
356
|
# File 'lib/cli/ui.rb', line 354
def enable_color=(bool)
@enable_color = !!bool
end
|
.enable_color? ⇒ Boolean
343
344
345
|
# File 'lib/cli/ui.rb', line 343
def enable_color?
@enable_color
end
|
.enable_cursor=(bool) ⇒ Object
374
375
376
|
# File 'lib/cli/ui.rb', line 374
def enable_cursor=(bool)
@enable_cursor = !!bool
end
|
.enable_cursor? ⇒ Boolean
363
364
365
|
# File 'lib/cli/ui.rb', line 363
def enable_cursor?
@enable_cursor
end
|
.fmt(input, enable_color: enable_color?)
) ⇒ Object
175
176
177
|
# File 'lib/cli/ui.rb', line 175
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, to: $stdout, &block) ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/cli/ui.rb', line 241
def frame(
text,
color: Frame::DEFAULT_FRAME_COLOR,
failure_text: nil,
success_text: nil,
timing: block_given?,
frame_style: Frame.frame_style,
to: $stdout,
&block
)
CLI::UI::Frame.open(
text,
color: color,
failure_text: failure_text,
success_text: success_text,
timing: timing,
frame_style: frame_style,
to: to,
&block
)
end
|
.frame_style=(frame_style) ⇒ Object
388
389
390
|
# File 'lib/cli/ui.rb', line 388
def frame_style=(frame_style)
Frame.frame_style = frame_style
end
|
.glyph(handle) ⇒ Object
46
47
48
|
# File 'lib/cli/ui.rb', line 46
def glyph(handle)
CLI::UI::Glyph.lookup(handle)
end
|
.link(url, text, format: true, blue_underline: format) ⇒ Object
394
395
396
397
398
399
400
|
# File 'lib/cli/ui.rb', line 394
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
.puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true, wrap: true) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/cli/ui.rb', line 202
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
330
331
332
333
334
335
336
|
# File 'lib/cli/ui.rb', line 330
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
58
59
60
61
62
63
64
65
|
# File 'lib/cli/ui.rb', line 58
def resolve_color(input)
case input
when CLI::UI::Color
input
else
CLI::UI::Color.lookup(input)
end
end
|
.resolve_style(input) ⇒ Object
.resolve_text(input, truncate_to: nil, enable_color: enable_color?)
) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/cli/ui.rb', line 153
def resolve_text(input, truncate_to: nil, enable_color: enable_color?)
formatted = CLI::UI::Formatter.new(input).format(enable_color: enable_color)
return formatted unless truncate_to
CLI::UI::Truncater.call(formatted, truncate_to)
end
|
.spinner(title, auto_debrief: true, &block) ⇒ Object
274
275
276
|
# File 'lib/cli/ui.rb', line 274
def spinner(title, auto_debrief: true, &block)
CLI::UI::Spinner.spin(title, auto_debrief: auto_debrief, &block)
end
|
.with_frame_color(color, &block) ⇒ Object
.wrap(input) ⇒ Object
180
181
182
|
# File 'lib/cli/ui.rb', line 180
def wrap(input)
CLI::UI::Wrap.new(input).wrap
end
|