fix: nil guards on w and h in all view functions

Prevents crash when backend-size returns nil for height.
Defaults to 80x24 if dimensions are nil or invalid.
This commit is contained in:
2026-05-14 13:41:15 -04:00
parent c4c1629816
commit 337b8cdd86
2 changed files with 20 additions and 7 deletions

View File

@@ -59,7 +59,9 @@ Returns a list of strings, one per line."
(nreverse lines)))
(defun view-status (fb w h)
(let* ((bg (theme-color :status-bg))
(let* ((w (or (and (numberp w) (> w 0) w) 80))
(h (or (and (numberp h) (> h 0) h) 24))
(bg (theme-color :status-bg))
(fg (theme-color :status-fg))
(ver (st :daemon-version))
(ver-str (if ver (format nil " v~a" ver) ""))
@@ -94,7 +96,9 @@ Returns a list of strings, one per line."
(if (string= result "") content result))))
(defun view-chat (fb w h)
(let* ((msgs (st :messages)) (total (length msgs))
(let* ((w (or (and (numberp w) (> w 0) w) 80))
(h (or (and (numberp h) (> h 0) h) 24))
(msgs (st :messages)) (total (length msgs))
(max-lines (- h 4)) (is-search (st :search-mode)) (y 0))
(when is-search
(let* ((matches (st :search-matches)) (idx (st :search-match-idx))
@@ -209,7 +213,9 @@ Returns a list of strings, one per line."
** Input Line
#+BEGIN_SRC lisp :tangle /home/user/.local/share/passepartout/lisp/channel-tui-view.lisp
(defun view-input (fb w h)
(let* ((text (input-string))
(let* ((w (or (and (numberp w) (> w 0) w) 80))
(h (or (and (numberp h) (> h 0) h) 24))
(text (input-string))
(pos (or (st :cursor-pos) 0))
(display-start (max 0 (- pos (1- w))))
(visible (subseq text display-start (min (length text) (+ display-start w)))))
@@ -222,7 +228,9 @@ Returns a list of strings, one per line."
#+BEGIN_SRC lisp :tangle /home/user/.local/share/passepartout/lisp/channel-tui-view.lisp
(defun view-sidebar (fb w h)
"Render the right-side sidebar panel with warm colors."
(let* ((x (- w (or (st :sidebar-width) 30)))
(let* ((w (or (and (numberp w) (> w 0) w) 80))
(h (or (and (numberp h) (> h 0) h) 24))
(x (- w (or (st :sidebar-width) 30)))
(y 0))
;; Vertical separator
(dotimes (row h)
@@ -266,6 +274,8 @@ Returns a list of strings, one per line."
** Redraw (dirty-flag dispatch)
#+begin_src lisp
(defun redraw (fb w h)
(setq w (or (and (numberp w) (> w 0) w) 80)
h (or (and (numberp h) (> h 0) h) 24))
(destructuring-bind (sd cd id) (st :dirty)
(when sd (view-status fb w h))
(when cd (view-chat fb w h))

View File

@@ -406,9 +406,12 @@ case "$COMMAND" in
(sleep 3) (finish-output) (uiop:quit 1))))
(passepartout.channel-tui:tui-main))
LISPEOF
# Export terminal dimensions — bash sets COLUMNS/LINES but
# doesn't export them to subprocesses by default.
export COLUMNS LINES
# Set terminal dimensions from stty — bash's $COLUMNS/$LINES
# are often missing or not exported. stty size always works.
local ts=$(stty size 2>/dev/null)
export COLUMNS="${ts#* }" LINES="${ts% *}"
[ -z "$COLUMNS" ] && COLUMNS=80
[ -z "$LINES" ] && LINES=24
# Clear stale cl-tty cache to ensure latest backend-size fixes
find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null
exec sbcl --noinform --load /tmp/tui-load.lisp