Fix demo: use correct function signatures and keyword args

- draw-border needs :style keyword before :single/:double
- draw-text needs fg and bg color keywords
- demo renders correctly in a real terminal
- Tested with: (sleep 2; echo q) | script -q -c 'sbcl --script demo.lisp'
This commit is contained in:
Hermes
2026-05-11 21:33:35 +00:00
parent 825980b93b
commit 5a053b69c6

View File

@@ -5,73 +5,66 @@
(ql:register-local-projects)
(ql:quickload :cl-tty :silent t)
(in-package :cl-tty)
;; ─── Helper: write a string at (x, y) with optional styling ────────────────
(defun write-at (backend x y string &key fg bg bold)
(let ((styled (if bold (format nil "~c[1m~a~c[0m" #\Esc string #\Esc) string)))
(backend-write backend x y styled fg bg)))
;; ─── Demo ───────────────────────────────────────────────────────────────────
(defun run-demo ()
(let* ((backend (make-instance 'cl-tty.backend:modern-backend))
(w 80) (h 24))
(let ((backend (make-instance 'cl-tty.backend:modern-backend))
(read-fn (symbol-function (find-symbol "READ-RAW-BYTE" :cl-tty.input))))
;; Initialize
(initialize-backend backend)
(clear-screen backend)
(backend-write backend 0 0 (format nil "~c[?25l" #\Esc)) ; hide cursor
(cl-tty.backend:initialize-backend backend)
(cl-tty.backend:backend-clear backend)
(cl-tty.backend:cursor-hide backend)
;; Title box
(draw-border backend 1 1 78 3 :double :title " cl-tty Demo ")
(write-at backend 3 2 "A pure-CL terminal UI framework. No ncurses, no FFI."
:bold t)
(cl-tty.backend:draw-border backend 1 1 78 3 :style :double :title " cl-tty Demo ")
(cl-tty.backend:draw-text backend 3 2
"A pure-CL terminal UI framework. No ncurses, no FFI."
:white :default :bold t)
;; Feature grid
(draw-border backend 1 5 78 12 :single :title " Components ")
(let ((items '((" Box Bordered containers with title and background"
" Text Styled text with word-wrap and spans")
(" ScrollBox Scrollable viewport with scrollbars"
" TabBar Horizontal tab navigation")
(" Select Dropdown with fuzzy filter"
" TextInput / TextArea Single/multi-line input with undo")
(" Markdown Renders markdown with syntax highlighting"
" Dialog / Toast Modal overlays and notifications")
(" Mouse Event handlers and text selection"
" Slot System Named slots for extensible UI"))))
(loop for i from 0 below 5
for (col1 col2) = (nth i items)
do (write-at backend 3 (+ 7 i) col1)
(write-at backend 42 (+ 7 i) col2)))
;; Components grid
(cl-tty.backend:draw-border backend 1 5 78 12 :style :single :title " Components ")
(loop for i from 0 below 5
for item = (nth i '((" Box Bordered containers with title and background"
" Text Styled text with word-wrap and spans")
(" ScrollBox Scrollable viewport with scrollbars"
" TabBar Horizontal tab navigation")
(" Select Dropdown with fuzzy filter"
" TextInput / TextArea Single/multi-line input with undo")
(" Markdown Renders markdown with syntax highlighting"
" Dialog / Toast Modal overlays and notifications")
(" Mouse Event handlers and text selection"
" Slot System Named slots for extensible UI")))
do (cl-tty.backend:draw-text backend 3 (+ 7 i) (first item) :white :default)
(cl-tty.backend:draw-text backend 42 (+ 7 i) (second item) :white :default))
;; Backend features table
(draw-border backend 1 18 78 5 :single :title " Backend Support ")
(write-at backend 3 20 "Feature" :bold t)
(write-at backend 25 20 "modern" :bold t)
(write-at backend 40 20 "simple" :bold t)
(write-at backend 3 21 "Truecolor (24-bit)")
(write-at backend 25 21 "yes")
(write-at backend 40 21 "no")
(write-at backend 3 22 "OSC 8 hyperlinks")
(write-at backend 25 22 "yes")
(write-at backend 40 22 "no")
(cl-tty.backend:draw-border backend 1 18 78 5 :style :single :title " Backend Support ")
(cl-tty.backend:draw-text backend 3 20 "Feature" :bright-white :default :bold t)
(cl-tty.backend:draw-text backend 25 20 "modern" :bright-white :default :bold t)
(cl-tty.backend:draw-text backend 40 20 "simple" :bright-white :default :bold t)
(cl-tty.backend:draw-text backend 3 21 "Truecolor (24-bit)" :white :default)
(cl-tty.backend:draw-text backend 25 21 "yes" :green :default)
(cl-tty.backend:draw-text backend 40 21 "no" :red :default)
(cl-tty.backend:draw-text backend 3 22 "OSC 8 hyperlinks" :white :default)
(cl-tty.backend:draw-text backend 25 22 "yes" :green :default)
(cl-tty.backend:draw-text backend 40 22 "no" :red :default)
;; Footer
(write-at backend 1 24 " Press q to quit " :bold t :fg :white :bg :blue)
(backend-write backend 0 0 (format nil "~c[?25h" #\Esc)) ; show cursor
;; Footer bar
(cl-tty.backend:draw-rect backend 1 24 78 1 :bg :blue)
(cl-tty.backend:draw-text backend 2 24 " Press q to quit " :bright-white :blue :bold t)
;; Wait for q
(cl-tty.backend:cursor-show backend)
;; Wait for q keypress
(loop
(let ((ch (read-raw-byte :timeout 1)))
(let ((ch (funcall read-fn :timeout 1)))
(when ch
(when (or (char= (code-char ch) #\q)
(= ch 3)) ; Ctrl+C
(when (or (char= (code-char ch) #\q) (= ch 3))
(return)))))
;; Cleanup
(clear-screen backend)
(shutdown-backend backend)))
(cl-tty.backend:backend-clear backend)
(cl-tty.backend:shutdown-backend backend)))
;; ─── Run ────────────────────────────────────────────────────────────────────