module CLI::UI::Widgets

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}}"))

Constants

MAP

Public Class Methods

available() click to toggle source

All available widgets by name

# File lib/cli/ui/widgets.rb, line 46
def self.available
  MAP.keys
end
lookup(handle) click to toggle source

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)`

# File lib/cli/ui/widgets.rb, line 38
def self.lookup(handle)
  MAP.fetch(handle.to_s).call
rescue KeyError, NameError
  raise(InvalidWidgetHandle, handle)
end
register(name, &cb) click to toggle source
# File lib/cli/ui/widgets.rb, line 23
def self.register(name, &cb)
  MAP[name] = cb
end