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.0.0'
Class Method Summary
collapse
-
.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
-
.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, &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) ⇒ 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
.ask(question, options: nil, default: nil, is_file: false, allow_empty: true, multiple: false, filter_ui: true, select_ui: true, &options_proc) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cli/ui.rb', line 106
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
337
338
339
|
# File 'lib/cli/ui.rb', line 337
def enable_color=(bool)
@enable_color = !!bool
end
|
.enable_color? ⇒ Boolean
326
327
328
|
# File 'lib/cli/ui.rb', line 326
def enable_color?
@enable_color
end
|
.fmt(input, enable_color: enable_color?)
) ⇒ Object
161
162
163
|
# File 'lib/cli/ui.rb', line 161
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/cli/ui.rb', line 226
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
351
352
353
|
# File 'lib/cli/ui.rb', line 351
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
|
.link(url, text, format: true, blue_underline: format) ⇒ Object
357
358
359
360
361
362
363
|
# File 'lib/cli/ui.rb', line 357
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/cli/ui.rb', line 288
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/cli/ui.rb', line 188
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
313
314
315
316
317
318
319
|
# File 'lib/cli/ui.rb', line 313
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
139
140
141
142
143
144
|
# File 'lib/cli/ui.rb', line 139
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
257
258
259
|
# File 'lib/cli/ui.rb', line 257
def spinner(title, auto_debrief: true, &block)
CLI::UI::Spinner.spin(title, auto_debrief: auto_debrief, &block)
end
|
.with_frame_color(color, &block) ⇒ Object
273
274
275
|
# File 'lib/cli/ui.rb', line 273
def with_frame_color(color, &block)
CLI::UI::Frame.with_frame_color_override(color, &block)
end
|
.wrap(input) ⇒ Object
166
167
168
|
# File 'lib/cli/ui.rb', line 166
def wrap(input)
CLI::UI::Wrap.new(input).wrap
end
|