v0.3.3: SIGWINCH, scroll clamp, /quit, /reconnect, history, message vector
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
SIGWINCH: handle KEY_RESIZE (410) in main loop — re-measure screen, re-create status/chat/input windows at new dimensions, force redraw. Scroll clamp: PageUp clamped to (max 0 (- total 1)), prevents scrolling past message list end. Status bar shows 'msgs:N scroll:0'. /quit: saves :input-history to ~/.cache/passepartout/history (one line per entry, most recent first), sends goodbye handshake, sets :running nil. /reconnect: closes stale socket via disconnect-daemon, re-runs connect-daemon with retry backoff. Connection-loss detection: reader-loop counts consecutive nils; after 10, queues :disconnected event. Handler clears :connected/:busy, shows red system message. Load-history: reads ~/.cache/passepartout/history on startup, populates :input-history for up-arrow recall. Message vector: :messages init as adjustable vector with fill pointer. add-msg uses vector-push-extend (O(1) append). view-chat uses aref (O(1) access) instead of nth (O(n) for lists).
This commit is contained in:
@@ -69,17 +69,17 @@ Returns list of trimmed strings. Single words wider than width are split."
|
||||
(clear win)
|
||||
(box win 0 0)
|
||||
(let* ((w (or (width win) 78))
|
||||
(msgs (reverse (st :messages)))
|
||||
(msgs (st :messages))
|
||||
(total (length msgs))
|
||||
(max-lines (- h 2))
|
||||
(y 1))
|
||||
;; Count visible messages from end, accounting for word wrap
|
||||
(let* ((msg-count 0)
|
||||
(lines-remaining max-lines))
|
||||
;; Walk from most recent backwards, counting wrapped lines
|
||||
(let ((visible-msgs (reverse msgs)))
|
||||
(loop for msg in visible-msgs
|
||||
while (> lines-remaining 0)
|
||||
do (let* ((role (getf msg :role))
|
||||
(loop for i from (1- total) downto 0
|
||||
while (> lines-remaining 0)
|
||||
do (let* ((msg (aref msgs i))
|
||||
(role (getf msg :role))
|
||||
(content (getf msg :content))
|
||||
(time (or (getf msg :time) ""))
|
||||
(prefix (case role (:user "⬆") (:agent "⬇") (t " ")))
|
||||
@@ -90,12 +90,11 @@ Returns list of trimmed strings. Single words wider than width are split."
|
||||
(progn (decf lines-remaining nlines) (incf msg-count))
|
||||
(setf lines-remaining 0))))
|
||||
;; Render from the correct starting message
|
||||
(let* ((total (length msgs))
|
||||
(scroll-skip (st :scroll-offset))
|
||||
(let* ((scroll-skip (st :scroll-offset))
|
||||
(start (max 0 (- total msg-count scroll-skip))))
|
||||
(loop for i from start below total
|
||||
while (< y (1- h))
|
||||
do (let* ((msg (nth i msgs))
|
||||
do (let* ((msg (aref msgs i))
|
||||
(role (getf msg :role))
|
||||
(content (getf msg :content))
|
||||
(time (or (getf msg :time) ""))
|
||||
@@ -106,7 +105,7 @@ Returns list of trimmed strings. Single words wider than width are split."
|
||||
(dolist (line wrapped)
|
||||
(when (< y (1- h))
|
||||
(add-string win line :y y :x 1 :n (1- w) :fgcolor color)
|
||||
(incf y)))))))))
|
||||
(incf y))))))))
|
||||
(refresh win))
|
||||
#+end_src
|
||||
|
||||
|
||||
Reference in New Issue
Block a user