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:
@@ -59,7 +59,9 @@ Returns a list of strings, one per line."
|
|||||||
(nreverse lines)))
|
(nreverse lines)))
|
||||||
|
|
||||||
(defun view-status (fb w h)
|
(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))
|
(fg (theme-color :status-fg))
|
||||||
(ver (st :daemon-version))
|
(ver (st :daemon-version))
|
||||||
(ver-str (if ver (format nil " v~a" ver) ""))
|
(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))))
|
(if (string= result "") content result))))
|
||||||
|
|
||||||
(defun view-chat (fb w h)
|
(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))
|
(max-lines (- h 4)) (is-search (st :search-mode)) (y 0))
|
||||||
(when is-search
|
(when is-search
|
||||||
(let* ((matches (st :search-matches)) (idx (st :search-match-idx))
|
(let* ((matches (st :search-matches)) (idx (st :search-match-idx))
|
||||||
@@ -209,7 +213,9 @@ Returns a list of strings, one per line."
|
|||||||
** Input Line
|
** Input Line
|
||||||
#+BEGIN_SRC lisp :tangle /home/user/.local/share/passepartout/lisp/channel-tui-view.lisp
|
#+BEGIN_SRC lisp :tangle /home/user/.local/share/passepartout/lisp/channel-tui-view.lisp
|
||||||
(defun view-input (fb w h)
|
(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))
|
(pos (or (st :cursor-pos) 0))
|
||||||
(display-start (max 0 (- pos (1- w))))
|
(display-start (max 0 (- pos (1- w))))
|
||||||
(visible (subseq text display-start (min (length text) (+ display-start 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
|
#+BEGIN_SRC lisp :tangle /home/user/.local/share/passepartout/lisp/channel-tui-view.lisp
|
||||||
(defun view-sidebar (fb w h)
|
(defun view-sidebar (fb w h)
|
||||||
"Render the right-side sidebar panel with warm colors."
|
"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))
|
(y 0))
|
||||||
;; Vertical separator
|
;; Vertical separator
|
||||||
(dotimes (row h)
|
(dotimes (row h)
|
||||||
@@ -266,6 +274,8 @@ Returns a list of strings, one per line."
|
|||||||
** Redraw (dirty-flag dispatch)
|
** Redraw (dirty-flag dispatch)
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defun redraw (fb w h)
|
(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)
|
(destructuring-bind (sd cd id) (st :dirty)
|
||||||
(when sd (view-status fb w h))
|
(when sd (view-status fb w h))
|
||||||
(when cd (view-chat fb w h))
|
(when cd (view-chat fb w h))
|
||||||
|
|||||||
@@ -406,9 +406,12 @@ case "$COMMAND" in
|
|||||||
(sleep 3) (finish-output) (uiop:quit 1))))
|
(sleep 3) (finish-output) (uiop:quit 1))))
|
||||||
(passepartout.channel-tui:tui-main))
|
(passepartout.channel-tui:tui-main))
|
||||||
LISPEOF
|
LISPEOF
|
||||||
# Export terminal dimensions — bash sets COLUMNS/LINES but
|
# Set terminal dimensions from stty — bash's $COLUMNS/$LINES
|
||||||
# doesn't export them to subprocesses by default.
|
# are often missing or not exported. stty size always works.
|
||||||
export COLUMNS LINES
|
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
|
# Clear stale cl-tty cache to ensure latest backend-size fixes
|
||||||
find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null
|
find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null
|
||||||
exec sbcl --noinform --load /tmp/tui-load.lisp
|
exec sbcl --noinform --load /tmp/tui-load.lisp
|
||||||
|
|||||||
Reference in New Issue
Block a user