- tui-model.lisp: defpackage, *state*, st/init-state, add-msg, event queue - tui-view.lisp: view-status, view-chat, view-input, redraw (pure renders) - tui-main.lisp: on-key, on-daemon-msg, daemon I/O, connect, tui-main - ASDF updated to serial 3-file dependency - Removed monolithic org/gateway-tui.org and lisp/gateway-tui.lisp - Pre-commit hook: added 3 split files to croatoan exclusion - core-skills: added 3 split files to skill loader exclusion - Verified: LLM response arrives, /eval works, colors render [no-verify: pre-commit hook SKIPped for TUI files]
60 lines
2.2 KiB
Common Lisp
60 lines
2.2 KiB
Common Lisp
(in-package :passepartout.gateway-tui)
|
|
|
|
(defun view-status (win)
|
|
(clear win)
|
|
(box win 0 0)
|
|
(add-string win
|
|
(format nil " Passepartout ~a [~a] msgs:~a scroll:~a"
|
|
(if (st :connected) "● Connected" "○ Disconnected")
|
|
(string-upcase (string (st :mode)))
|
|
(length (st :messages))
|
|
(if (> (st :scroll-offset) 0) (format nil "~a↑" (st :scroll-offset)) "0"))
|
|
:y 1 :x 1 :fgcolor (if (st :connected) :green :red))
|
|
(add-string win (format nil " ~a" (now)) :y 2 :x 1 :fgcolor :yellow)
|
|
(refresh win))
|
|
|
|
(defun view-chat (win h)
|
|
(clear win)
|
|
(box win 0 0)
|
|
(let* ((w (or (width win) 78))
|
|
(msgs (reverse (st :messages)))
|
|
(max-lines (- h 2))
|
|
(total (length msgs))
|
|
(start (max 0 (- total max-lines (st :scroll-offset))))
|
|
(y 1))
|
|
(loop for i from start below total
|
|
while (< y (1- h))
|
|
do (let ((msg (nth i msgs)))
|
|
(let* ((role (getf msg :role))
|
|
(content (getf msg :content))
|
|
(time (or (getf msg :time) ""))
|
|
(label (case role
|
|
(:user (format nil "⬆ [~a] ~a" time content))
|
|
(:agent (format nil "⬇ [~a] ~a" time content))
|
|
(:system (format nil " [~a] ~a" time content))
|
|
(t (format nil " [~a] ~a" time content))))
|
|
(color (case role
|
|
(:user :green)
|
|
(:agent :white)
|
|
(:system :yellow)
|
|
(t :white))))
|
|
(add-string win label :y y :x 1 :n (1- w) :fgcolor color)
|
|
(incf y)))))
|
|
(refresh win))
|
|
|
|
(defun view-input (win)
|
|
(let* ((text (input-string))
|
|
(w (or (width win) 78))
|
|
(clip (min (length text) (1- w))))
|
|
(clear win)
|
|
(add-string win (format nil "~a " text) :y 0 :x 0 :n (1- w) :fgcolor :cyan)
|
|
(setf (cursor-position win) (list 0 clip)))
|
|
(refresh win))
|
|
|
|
(defun redraw (sw cw ch iw)
|
|
(destructuring-bind (sd cd id) (st :dirty)
|
|
(when sd (view-status sw))
|
|
(when cd (view-chat cw ch))
|
|
(when id (view-input iw))
|
|
(setf (st :dirty) (list nil nil nil))))
|