The Elm Architecture event loop for TUI applications.
A program consists of:
Commands are functions that produce messages asynchronously.
The Elm Architecture event loop for TUI applications. A program consists of: - init: Initial state and optional startup command - update: (state, msg) -> [new-state, cmd] - view: state -> string Commands are functions that produce messages asynchronously.
(batch & cmds)Combine multiple commands into one.
Combine multiple commands into one.
(cmd f)Create a command from a function that returns a message. The function will be called asynchronously.
Create a command from a function that returns a message. The function will be called asynchronously.
Command that sends a quit message.
Command that sends a quit message.
(run {:keys [init update view] :as opts})Run a TUI program.
Options: :init - (fn [] [initial-state cmd]) or initial state value :update - (fn [state msg] [new-state cmd]) :view - (fn [state] string) :alt-screen - Use alternate screen buffer (default: false) :mouse - Mouse mode: nil, :normal, :cell, or :all (default: nil) :focus-reporting - Report focus in/out (default: false) :fps - Frames per second (default: 60) :hide-cursor - Hide cursor (default: true)
The init function should return [initial-state cmd] or just initial-state. The update function receives (state msg) and returns [new-state cmd]. Commands are optional and can be nil.
Run a TUI program. Options: :init - (fn [] [initial-state cmd]) or initial state value :update - (fn [state msg] [new-state cmd]) :view - (fn [state] string) :alt-screen - Use alternate screen buffer (default: false) :mouse - Mouse mode: nil, :normal, :cell, or :all (default: nil) :focus-reporting - Report focus in/out (default: false) :fps - Frames per second (default: 60) :hide-cursor - Hide cursor (default: true) The init function should return [initial-state cmd] or just initial-state. The update function receives (state msg) and returns [new-state cmd]. Commands are optional and can be nil.
(run-simple {:keys [state update view] :as opts})Run a simple TUI program with minimal setup.
Takes a map with: :state - Initial state :update - (fn [state msg] [new-state cmd]) :view - (fn [state] string)
Example: (run-simple {:state {:count 0} :update (fn [state msg] (if (key-match? msg "q") [state quit-cmd] [(update state :count inc) nil])) :view (fn [state] (str "Count: " (:count state) "\nPress q to quit"))})
Run a simple TUI program with minimal setup.
Takes a map with:
:state - Initial state
:update - (fn [state msg] [new-state cmd])
:view - (fn [state] string)
Example:
(run-simple
{:state {:count 0}
:update (fn [state msg]
(if (key-match? msg "q")
[state quit-cmd]
[(update state :count inc) nil]))
:view (fn [state]
(str "Count: " (:count state) "\nPress q to quit"))})(sequence-cmds & cmds)Run commands in sequence (each waits for previous to complete).
Run commands in sequence (each waits for previous to complete).
(window-size-msg width height)Create a window size message.
Create a window size message.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |