Files
passepartout/org/gateway-tui-view.org
Amr Gharbeia 61ea5767d6
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 3s
v0.3.0 deferred: tab completion, multi-line, /help, activity indicator, context persistence, theming
- Tab completion: Tab key autocompletes / commands (Tab handler in on-key)
- Multi-line input: backslash + Enter inserts literal newline instead of sending
- /help command: displays full command listing with descriptions
- Activity indicator: :busy flag shows "...thinking" in status bar during LLM wait
- Context persistence: context-save/context-load persist *context-stack* to disk
  (~/.cache/passepartout/context.lisp). Auto-restores on skill load.
  Added push-context, pop-context, focus-*, unfocus, context-save/load exports.
- Theming: *tui-theme* plist with semantic color roles, /theme command
  View functions (view-chat, view-status, view-input) use theme-color
- TUI test suite: 19 tests, 53 checks (100% pass)
- Context test suite: 2 tests, 6 checks (100% pass)
- Total: 5 suites, 81 checks, 0 failures
2026-05-05 18:02:50 -04:00

93 lines
3.3 KiB
Org Mode

#+TITLE: Passepartout TUI — View
#+PROPERTY: header-args:lisp :tangle ../lisp/gateway-tui-view.lisp
* View
Pure render functions. Each takes a Croatoan window and current state.
State is read via ~(st :key)~ — no mutation here.
** Contract
1. (view-status win): renders the status bar with connection info,
version, and timestamp.
2. (view-chat win h): renders the scrolled chat message list. Takes
window and available height. Messages are color-coded: green (user),
white (agent), yellow (system).
3. (view-input win): renders the input line with cursor and typing
indicator.
4. (redraw sw cw ch iw): dispatches redraws based on ~(st :dirty)~
flags (status, chat, input). Minimizes terminal writes.
** Status Bar
#+begin_src 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~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")
(if (st :busy) " …thinking" ""))
:y 1 :x 1 :fgcolor (theme-color (if (st :connected) :connected :disconnected)))
(add-string win (format nil " ~a" (now)) :y 2 :x 1 :fgcolor (theme-color :timestamp))
(refresh win))
#+end_src
** Chat Area
#+begin_src lisp
(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 (theme-color (case role
(:user :user)
(:agent :agent)
(:system :system)
(t :agent)))))
(add-string win label :y y :x 1 :n (1- w) :fgcolor color)
(incf y)))))
(refresh win))
#+end_src
** Input Line
#+begin_src lisp
(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 (theme-color :input))
(setf (cursor-position win) (list 0 clip)))
(refresh win))
#+end_src
** Redraw (dirty-flag dispatch)
#+begin_src lisp
(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))))
#+end_src