The terminal edge: TTY detection, size, cursor control, in-place redraw
and raw keyboard input. Decisions live in pure helpers here (frame-string,
parse-stty-size, pick-width); the functions ending in ! only print or
run stty.
The terminal edge: TTY detection, size, cursor control, in-place redraw and raw keyboard input. Decisions live in pure helpers here (`frame-string`, `parse-stty-size`, `pick-width`); the functions ending in `!` only print or run `stty`.
(frame-height {:keys [frame]})How many rows frame-string leaves redrawable for this frame.
How many rows `frame-string` leaves redrawable for this frame.
(frame-string prev-height {:keys [emit frame]})The text that redraws a frame in place. prev-height is the number of
frame lines printed last time (see frame-height). Lines in :emit are
printed permanently where the old frame started; :frame lines follow and
stay redrawable. Each line replaces whatever was on its row, and anything
left over from a taller previous frame is cleared.
The text that redraws a frame in place. `prev-height` is the number of frame lines printed last time (see `frame-height`). Lines in `:emit` are printed permanently where the old frame started; `:frame` lines follow and stay redrawable. Each line replaces whatever was on its row, and anything left over from a taller previous frame is cleared.
Escape sequence that hides the cursor.
Escape sequence that hides the cursor.
(parse-stty-size s)Parses stty size output ("rows cols") into {:rows n :cols n}, or nil.
Parses `stty size` output ("rows cols") into `{:rows n :cols n}`, or nil.
(pick-width stty-output columns-env)Terminal width from stty size output, else the COLUMNS value, else 80.
Terminal width from `stty size` output, else the COLUMNS value, else 80.
(prompt! label buffer)Draws a one-line prompt in place: label> buffer. A nil buffer closes
the prompt by moving to a fresh line.
Draws a one-line prompt in place: `label> buffer`. A nil `buffer` closes the prompt by moving to a fresh line.
(read-key!)A pending key press as a character, without waiting, or nil. A lone ESC
comes back as \u001b; escape sequences (arrows, function keys) are
swallowed and give nil. Call inside with-raw-mode!.
A pending key press as a character, without waiting, or nil. A lone ESC comes back as `\u001b`; escape sequences (arrows, function keys) are swallowed and give nil. Call inside `with-raw-mode!`.
(redraw! prev-height frame)Prints frame ({:emit [...] :frame [...]}) over the previous one and
returns the height to pass to the next call.
Prints `frame` (`{:emit [...] :frame [...]}`) over the previous one and
returns the height to pass to the next call.Escape sequence that shows the cursor.
Escape sequence that shows the cursor.
(stdin-tty?)True when stdin is a terminal, so raw mode and key presses make sense.
True when stdin is a terminal, so raw mode and key presses make sense.
(width)Current terminal width: stty size, then $COLUMNS, then 80.
Current terminal width: `stty size`, then $COLUMNS, then 80.
How often a live view re-reads the terminal width. Each read runs
stty; until it does, a resized terminal shows frames of the old width.
How often a live view re-reads the terminal width. Each read runs `stty`; until it does, a resized terminal shows frames of the old width.
(with-hidden-cursor! f)Runs (f) with the cursor hidden, and shows it again however f ends.
Runs `(f)` with the cursor hidden, and shows it again however `f` ends.
(with-raw-mode! f)(with-raw-mode! f after)Runs (f) with the terminal in raw-ish mode (no line buffering, no echo)
and restores the saved settings when f ends, throws, or the JVM exits.
after, when given, runs right after the restore, in the same shutdown
hook: JVM shutdown hooks run concurrently, so cleanup that kills child
processes must not race the stty that restores the terminal.
Runs `(f)` with the terminal in raw-ish mode (no line buffering, no echo) and restores the saved settings when `f` ends, throws, or the JVM exits. `after`, when given, runs right after the restore, in the same shutdown hook: JVM shutdown hooks run concurrently, so cleanup that kills child processes must not race the `stty` that restores the terminal.
(with-restore! restore f)Runs (f) and then runs (restore), also if f throws and also on
Ctrl-C or any JVM exit, through a shutdown hook. restore must be safe to
call twice.
Runs `(f)` and then runs `(restore)`, also if `f` throws and also on Ctrl-C or any JVM exit, through a shutdown hook. `restore` must be safe to call twice.
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 |