Module: CLI::UI::Widgets
- Defined in:
- lib/cli/ui/widgets.rb,
lib/cli/ui/widgets/base.rb,
lib/cli/ui/widgets/status.rb
Overview
Widgets are formatter objects with more custom implementations than the other features, which all center around formatting text with colours, etc.
If you want to extend CLI::UI with your own widgets, you may want to do something like this:
require('cli/ui')
class MyWidget < CLI::UI::Widgets::Base
# ...
end
CLI::UI::Widgets.register('my-widget') { MyWidget }
puts(CLI::UI.fmt("{{@widget/my-widget:args}}"))
Defined Under Namespace
Classes: Base, InvalidWidgetArguments, InvalidWidgetHandle, Status
Constant Summary collapse
- MAP =
{}
Class Method Summary collapse
-
.available ⇒ Object
All available widgets by name.
-
.lookup(handle) ⇒ Object
Looks up a widget by handle.
-
.register(name, &cb) ⇒ Object
: (String name) { -> singleton(Widgets::Base) } -> void.
Class Method Details
.available ⇒ Object
All available widgets by name
: -> Array
51 52 53 |
# File 'lib/cli/ui/widgets.rb', line 51 def available MAP.keys end |
.lookup(handle) ⇒ Object
Looks up a widget by handle
Raises
Raises InvalidWidgetHandle if the widget is not available.
Returns
A callable widget, to be invoked like ‘.call(argstring)`
: (String handle) -> singleton(Widgets::Base)
42 43 44 45 46 |
# File 'lib/cli/ui/widgets.rb', line 42 def lookup(handle) MAP.fetch(handle).call rescue KeyError, NameError raise(InvalidWidgetHandle, handle) end |
.register(name, &cb) ⇒ Object
: (String name) { -> singleton(Widgets::Base) } -> void
29 30 31 |
# File 'lib/cli/ui/widgets.rb', line 29 def register(name, &cb) MAP[name] = cb end |