clojuressh.terminal
carriage-return
ctrl-c
enter-raw-mode
(enter-raw-mode quiet)Put stdin into raw mode, matching the semantics of the original BbsshUtils C implementation.
quiet (zero or non-zero, like the C int) suppresses the perror-style diagnostic printed to stderr on syscall failure on POSIX. On Windows the argument is accepted but the C original is silent either way, so it is effectively ignored.
Failures do not throw; on failure the previous mode is left in place.
get-height
(get-height)Return the height (rows) of the terminal.
See get-width for behaviour and preconditions.
get-width
(get-width)Return the width (columns) of the terminal.
Uses query-terminal-size, which briefly puts the terminal into raw mode and queries it via ANSI DSR. The terminal’s prior state is restored before this function returns. Returns nil if the terminal cannot be queried.
in-raw-mode?
(in-raw-mode?)Probe the current terminal state on stdin and return true if it looks like raw mode.
On POSIX: true when both ICANON and ECHO are cleared on stdin’s termios. This detects raw mode regardless of which library or process put the terminal into it, not just raw mode set by enter-raw-mode in this namespace.
On Windows: true when ENABLE_ECHO_INPUT is cleared on stdin’s console mode, matching the single bit that enter-raw-mode toggles there.
Returns false (not nil) on any error — e.g. stdin is not a terminal, or the underlying syscall fails.
is-terminal?
(is-terminal?)Returns true if stdout is connected to a terminal.
Uses System/console, which returns nil when the JVM’s standard streams are not attached to a terminal (e.g. redirected to a file or piped). No shell process is invoked.
leave-raw-mode
(leave-raw-mode quiet)Restore stdin echo/canonical settings after enter-raw-mode.
On POSIX this restores the exact termios snapshot captured by the most recent successful enter-raw-mode call, and is a no-op if we are not currently in raw mode. On Windows it unconditionally re-enables ENABLE_ECHO_INPUT, matching the C original.
raw-mode-readline
(raw-mode-readline)Read input from stdin with terminal in raw mode.
The terminal’s prior state is restored on every exit path, including when the read loop throws.
restore-terminal-state
(restore-terminal-state state)Restore stdin to the state previously captured by save-terminal-state. Pass exactly what was returned from save-terminal-state.
Returns true on success, false on any failure (state is nil or the syscall fails).
save-terminal-state
(save-terminal-state)Capture the current terminal state of stdin and return an opaque value that can later be passed to restore-terminal-state to put the terminal back the way it was.
On POSIX the returned value is a byte[] containing the full struct termios. On Windows it is a Long containing the stdin console-mode DWORD. Returns nil if the underlying syscall fails (e.g. stdin is not a terminal).