Make text safe to write to a terminal.
A TUI usually renders data its user did not author - filenames, log lines, HTTP responses. Escape sequences in that data are instructions to the terminal, not characters: OSC 52 writes the attacker's data into the user's system clipboard, OSC 8 hyperlinks text to somewhere other than what it says, OSC 2 rewrites the window title, and CSI 2K with a carriage return erases the line the content just drew.
sanitize keeps the one sequence family that only paints characters - SGR,
the styling codes - and drops the rest. strip drops those too, leaving the
text that will actually be displayed.
Both return the argument unchanged when there is nothing to remove, so the common case of plain or styled text costs one scan and no allocation.
Make text safe to write to a terminal. A TUI usually renders data its user did not author - filenames, log lines, HTTP responses. Escape sequences in that data are instructions to the terminal, not characters: OSC 52 writes the attacker's data into the user's system clipboard, OSC 8 hyperlinks text to somewhere other than what it says, OSC 2 rewrites the window title, and CSI 2K with a carriage return erases the line the content just drew. `sanitize` keeps the one sequence family that only paints characters - SGR, the styling codes - and drops the rest. `strip` drops those too, leaving the text that will actually be displayed. Both return the argument unchanged when there is nothing to remove, so the common case of plain or styled text costs one scan and no allocation.
Help component for displaying key bindings.
Usage: (def bindings [{:key "j/k" :desc "up/down"} {:key "q" :desc "quit"}]) (def my-help (help bindings))
;; In view function: (help-view my-help)
Help component for displaying key bindings.
Usage:
(def bindings [{:key "j/k" :desc "up/down"}
{:key "q" :desc "quit"}])
(def my-help (help bindings))
;; In view function:
(help-view my-help)Scrollable list component with item selection.
Usage: (def my-list (item-list ["Apple" "Banana" "Cherry"]))
;; In update function: (list-update my-list msg)
;; In view function: (list-view my-list)
Scrollable list component with item selection. Usage: (def my-list (item-list ["Apple" "Banana" "Cherry"])) ;; In update function: (list-update my-list msg) ;; In view function: (list-view my-list)
Pagination component for displaying page indicators.
Usage: (def pager (paginator :total-pages 5))
;; In update function: (paginator-update pager msg)
;; In view function: (paginator-view pager)
Pagination component for displaying page indicators. Usage: (def pager (paginator :total-pages 5)) ;; In update function: (paginator-update pager msg) ;; In view function: (paginator-view pager)
Progress bar component.
Usage: (def my-progress (progress-bar :width 40))
;; Update progress (0.0 to 1.0): (set-progress my-progress 0.5)
;; In view function: (progress-view my-progress)
Progress bar component. Usage: (def my-progress (progress-bar :width 40)) ;; Update progress (0.0 to 1.0): (set-progress my-progress 0.5) ;; In view function: (progress-view my-progress)
Animated spinner component.
Usage: (def my-spinner (spinner :dots))
;; In update function: (spinner-update my-spinner msg)
;; In view function: (spinner-view my-spinner)
Animated spinner component. Usage: (def my-spinner (spinner :dots)) ;; In update function: (spinner-update my-spinner msg) ;; In view function: (spinner-view my-spinner)
Table component with aligned columns, optional borders, and row cursor.
Usage: (def tbl (table [{:title "Name" :width 20} {:title "Value" :width 30}] [["foo" "bar"] ["baz" "qux"]] :cursor 0))
;; In update function: (table-update tbl msg)
;; In view function: (table-view tbl)
Table component with aligned columns, optional borders, and row cursor.
Usage:
(def tbl (table [{:title "Name" :width 20} {:title "Value" :width 30}]
[["foo" "bar"] ["baz" "qux"]]
:cursor 0))
;; In update function:
(table-update tbl msg)
;; In view function:
(table-view tbl)Text input component with cursor movement and editing.
Usage: (def my-input (text-input :prompt "Name: "))
;; In update function: (text-input-update my-input msg)
;; In view function: (text-input-view my-input)
Text input component with cursor movement and editing. Usage: (def my-input (text-input :prompt "Name: ")) ;; In update function: (text-input-update my-input msg) ;; In view function: (text-input-view my-input)
Countdown timer component.
Usage: (def my-timer (timer :timeout 60000)) ; 60 seconds
;; In update function: (timer-update my-timer msg)
;; In view function: (timer-view my-timer)
Countdown timer component. Usage: (def my-timer (timer :timeout 60000)) ; 60 seconds ;; In update function: (timer-update my-timer msg) ;; In view function: (timer-view my-timer)
Scrollable text area component.
Displays a window into pre-rendered (possibly styled) text content.
Usage: (def vp (viewport "Long text content..." :height 10))
;; In update function: (viewport-update vp msg)
;; In view function: (viewport-view vp)
Scrollable text area component. Displays a window into pre-rendered (possibly styled) text content. Usage: (def vp (viewport "Long text content..." :height 10)) ;; In update function: (viewport-update vp msg) ;; In view function: (viewport-view vp)
Message types for charm.clj TUI applications.
Messages are plain maps with a :type key for easy pattern matching. Use factory functions to create messages and predicates to check types.
Message types for charm.clj TUI applications. Messages are plain maps with a :type key for easy pattern matching. Use factory functions to create messages and predicates to check types.
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.
Border rendering for styled boxes.
Provides predefined border styles and functions for rendering borders around text content.
Border rendering for styled boxes. Provides predefined border styles and functions for rendering borders around text content.
Main styling API.
Create styles as maps and apply them to text.
Example: (def my-style (style :fg (rgb 255 0 0) :bold true :padding [1 2])) (render my-style "Hello!") ; => styled text
Main styling API. Create styles as maps and apply them to text. Example: (def my-style (style :fg (rgb 255 0 0) :bold true :padding [1 2])) (render my-style "Hello!") ; => styled text
Layout utility for compositing a floating panel on top of base content.
Not a stateful component - just pure functions for overlay placement.
Usage: (place-overlay base-text overlay-text 5 3) (center-overlay base-text overlay-text)
Layout utility for compositing a floating panel on top of base content. Not a stateful component - just pure functions for overlay placement. Usage: (place-overlay base-text overlay-text 5 3) (center-overlay base-text overlay-text)
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 |