1.1--- a/lisp/lib/cli/tests/pkg.lisp Tue Oct 01 21:52:17 2024 -0400
1.2+++ b/lisp/lib/cli/tests/pkg.lisp Tue Oct 01 22:29:08 2024 -0400
1.3@@ -7,202 +7,9 @@
1.4 (:use :cl :std :rt :cli :cli/shell :cli/progress :cli/spark :cli/repl :cli/ansi :cli/prompt :cli/clap :cli/tools/sbcl :dat/sxp))
1.5
1.6 (in-package :cli/tests)
1.7-(declaim (optimize (debug 3) (safety 3)))
1.8 (defsuite :cli)
1.9 (in-suite :cli)
1.10
1.11-(defun ansi-t01 ()
1.12- (erase)
1.13- (cursor-position 0 0)
1.14- (princ "0")
1.15- (cursor-position 2 2)
1.16- (princ "1")
1.17- (cursor-position 5 15)
1.18- (princ "test")
1.19- (cursor-position 10 15)
1.20- (force-output)
1.21- (with-input-from-string (in (format nil "test~%~%"))
1.22- (let ((a (read-line in)))
1.23- (cursor-position 12 15)
1.24- (princ a)
1.25- (force-output))))
1.26-
1.27-(defun ansi-t02 ()
1.28- (print "normal")
1.29- (.sgr 1)
1.30- (print "bold")
1.31- (.sgr 4)
1.32- (print "bold underline")
1.33- (.sgr 7)
1.34- (print "bold underline reverse")
1.35- (.sgr 22)
1.36- (print "underline reverse")
1.37- (.sgr 24)
1.38- (print "reverse")
1.39- (.sgr 27)
1.40- (print "normal")
1.41- (.sgr 1 4 7)
1.42- (print "bold underline reverse")
1.43- (.sgr 0)
1.44- (print "normal")
1.45- (force-output))
1.46-
1.47-(defun ansi-t03 ()
1.48- "Display the 256 color palette."
1.49- (clear)
1.50- (loop for i from 0 to 255 do
1.51- (.sgr 48 5 i)
1.52- (princ #\space))
1.53- (terpri)
1.54- (.sgr 0)
1.55- (loop for i from 0 to 255 do
1.56- (.sgr 38 5 i)
1.57- (princ "X"))
1.58- (.sgr 0)
1.59- (force-output)
1.60- ;; (sleep 3)
1.61- (.ris)
1.62- (force-output))
1.63-
1.64-(defun ansi-t04 ()
1.65- "Hide and show the cursor."
1.66- (princ "Cursor visible:")
1.67- (force-output)
1.68- ;; (sleep 2)
1.69- (terpri)
1.70- (princ "Cursor invisible:")
1.71- (hide-cursor)
1.72- (force-output)
1.73- ;; (sleep 2)
1.74- (terpri)
1.75- (princ "Cursor visible:")
1.76- (show-cursor)
1.77- (force-output)
1.78- ;; (sleep 2)
1.79- )
1.80-
1.81-(defun ansi-t05 ()
1.82- "Switch to and back from the alternate screen buffer."
1.83- (princ "Normal screen buffer. ")
1.84- (force-output)
1.85- ;; (sleep 2)
1.86- (save-cursor-position)
1.87- (use-alternate-screen-buffer)
1.88- (clear)
1.89- (princ "Alternate screen buffer.")
1.90- (force-output)
1.91- ;; (sleep 2)
1.92- (use-normal-screen-buffer)
1.93- (restore-cursor-position)
1.94- (princ "Back to Normal screen buffer.")
1.95- (force-output)
1.96- ;; (sleep 1)
1.97- )
1.98-
1.99-(defun ansi-t06 ()
1.100- "Set individual termios flags to enable raw and disable echo mode.
1.101-
1.102-Enabling raw mode allows read-char to return immediately after a key is pressed.
1.103-
1.104-In the default cooked mode, the entry has to be confirmed by pressing enter."
1.105- (set-tty-mode t :ignbrk nil
1.106- :brkint nil
1.107- :parmrk nil
1.108- :istrip nil
1.109- :inlcr nil
1.110- :igncr nil
1.111- :icrnl nil
1.112- :ixon nil
1.113- :opost nil
1.114- :echo nil
1.115- :echonl nil
1.116- :icanon nil
1.117- :isig nil
1.118- :iexten nil
1.119- :csize nil
1.120- :parenb nil
1.121- :vmin 1
1.122- :vtime 0)
1.123- (erase)
1.124- (cursor-position 1 1)
1.125- (force-output)
1.126- (let ((a (read-char)))
1.127- (cursor-position 10 5)
1.128- (princ a)
1.129- (force-output))
1.130-
1.131- (set-tty-mode t :echo t
1.132- :brkint t
1.133- :ignpar t
1.134- :istrip t
1.135- :icrnl t
1.136- :ixon t
1.137- :opost t
1.138- :isig t
1.139- :icanon t
1.140- :veol 0))
1.141-
1.142-(defun ansi-t07 ()
1.143- "Use combination modes that consist of several individual flags.
1.144-
1.145-Cooked and raw are opposite modes. Enabling cooked disbles raw and vice versa."
1.146- (set-tty-mode t :cooked nil)
1.147- (erase)
1.148- (cursor-position 1 1)
1.149- (force-output)
1.150- (let ((a (read-char)))
1.151- (cursor-position 3 1)
1.152- (princ a)
1.153- (force-output))
1.154- (set-tty-mode t :raw nil))
1.155-
1.156-(defun ansi-t08 ()
1.157- "Why doesnt calling the stty utility work?"
1.158- (uiop:run-program "stty raw -echo" :ignore-error-status t)
1.159- (erase)
1.160- (cursor-position 1 1)
1.161- (force-output)
1.162- (let ((a (read-char)))
1.163- (cursor-position 2 1)
1.164- (princ a)
1.165- (force-output))
1.166- (uiop:run-program "stty -raw echo" :ignore-error-status t))
1.167-
1.168-(defun ansi-t09 ()
1.169- "Query terminal size with ANSI escape sequences."
1.170- ;; Put the terminal into raw mode so we can read the "user input"
1.171- ;; of the reply char by char
1.172- ;; Turn off the echo or the sequence will be displayed
1.173- (set-tty-mode t :cooked nil :echo nil)
1.174- (save-cursor-position)
1.175- ;; Go to the bottom right corner of the terminal by attempting
1.176- ;; to go to some high value of row and column
1.177- (cursor-position 999 999)
1.178- (let (chars)
1.179- ;; The terminal returns an escape sequence to the standard input
1.180- (device-status-report)
1.181- (force-output)
1.182- ;; The reply isnt immediately available, the terminal does need
1.183- ;; some time to answer
1.184- (sleep 0.1)
1.185- ;; The reply has to be read as if the user typed an escape sequence
1.186- (loop for i = (read-char-no-hang *standard-input* nil)
1.187- until (null i)
1.188- do (push i chars))
1.189- ;; Put the terminal back into its initial cooked state
1.190- (set-tty-mode t :raw nil :echo t)
1.191- (restore-cursor-position)
1.192- ;; Return the read sequence as a list of characters.
1.193- (nreverse chars)))
1.194-
1.195-(deftest ansi ()
1.196- (with-input-from-string (in (format nil "~%~%"))
1.197- (ansi-t01)
1.198- (ansi-t02)
1.199- (ansi-t03)
1.200- (ansi-t04)
1.201- (ansi-t05)))
1.202-
1.203 ;; TODO: needs to be compiled outside scope of test - contender for
1.204 ;; fixture API
1.205 (defprompt tpfoo :prompt "testing:")