abstract class Fancyline::Widget
- Fancyline::Widget
- Reference
- Object
Overview
Base class for widgets. A widget can intercept key inputs to temporarily
take control of parts of a running prompt. Usually, a widget is enabled
by certain user-input: Hitting the "Up" key starts the Widget::History
,
while hitting "Tab" starts Widget::Autocomplete
.
To create a custom widget, add a key binding (Fancyline#actions
) which
then calls Context#start_widget
. The context will then proceed to
call Widget#start
, and calls Widget#handle
to handle input. When the
widget is removed (for whatever reason), Widget#stop
is called.
You can find an usage sample in samples/widget.cr
. Another good built-in
widget to study is Fancyline::Widget::History
.
Direct Known Subclasses
Defined in:
fancyline/widget.crfancyline/widget/completion.cr
fancyline/widget/history.cr
fancyline/widget/history_search.cr
Instance Method Summary
-
#handle(ctx : Context, char : Char) : Bool
Called on user-input.
-
#start(ctx : Context)
Called when the widget is activated.
-
#stop(ctx : Context)
Called when the widget is removed.
Instance Method Detail
Called on user-input. Return true
if you handeled the input, return
false
to handle it as normal input by the Context
.
The default implementation calls Context#stop_widget
to remove itself,
and returns false
.