abstract class Fancyline::Widget

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.cr
fancyline/widget/completion.cr
fancyline/widget/history.cr
fancyline/widget/history_search.cr

Instance Method Summary

Instance Method Detail

def handle(ctx : Context, char : Char) : Bool #

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.


[View source]
def start(ctx : Context) #

Called when the widget is activated.


[View source]
def stop(ctx : Context) #

Called when the widget is removed.


[View source]