shore
Types
Values
pub fn default_keybinds() -> Keybinds
A typical set of keybindings
- exit:
ctrl+x
- submit:
enter
- focus_clear:
escape
- focus_next:
tab
- focus_prv:
shift+tab
pub fn exit() -> Event(a)
Manually trigger the exit for your TUI. Normally this would be handled through the exit keybind.
pub fn keybinds(
exit exit: Key,
submit submit: Key,
focus_clear focus_clear: Key,
focus_next focus_next: Key,
focus_prev focus_prev: Key,
) -> Keybinds
Set keybinds for various shore level functions, such as moving between focusable elements such as input boxes and buttons, as well as exiting and triggering button events.
pub fn on_update() -> Redraw
Redraw in response to events. Suitable for infrequently changing state.
pub fn send(msg: a) -> Event(a)
Allows sending a message to your TUI from another actor. This can be used, for example, to push an event to your TUI, rather than have it poll.
pub fn spec(
init init: fn() -> #(a, List(fn() -> b)),
view view: fn(a) -> Node(b),
update update: fn(a, b) -> #(a, List(fn() -> b)),
exit exit: Subject(Nil),
keybinds keybinds: Keybinds,
redraw redraw: Redraw,
) -> Spec(a, b)
A shore application is made up of these base parts. Following The Elm Architecture, you must define an init, view and update function which shore will handle calling.
Additionally, a simple subject to pass the exit call to is required. keybinding for the framework level events such as exiting and ui focusing. And finally redraw for defining when the applicaiton should be redrawn, either on update messages or on a timer.
Example
import gleam/erlang/process
import shore
pub fn main() {
let exit = process.new_subject()
let assert Ok(_actor) =
shore.spec(
init:,
update:,
view:,
exit:,
keybinds: shore.default_keybinds(),
redraw: shore.on_timer(16),
)
|> shore.start
exit |> process.receive_forever
}