Mercurial > core / lisp/lib/cli/tests/ansi.lisp
changeset 689: |
2e7d93b892a5 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 01 Oct 2024 22:29:08 -0400 |
permissions: |
-rw-r--r-- |
description: |
cli shell tests init |
1 ;;; ansi.lisp --- ANSI Tests 6 (in-package :cli/tests) 15 (cursor-position 5 15) 17 (cursor-position 10 15) 19 (with-input-from-string (in (format nil "test~%~%")) 20 (let ((a (read-line in))) 21 (cursor-position 12 15) 30 (print "bold underline") 32 (print "bold underline reverse") 34 (print "underline reverse") 40 (print "bold underline reverse") 46 "Display the 256 color palette." 48 (loop for i from 0 to 255 do 53 (loop for i from 0 to 255 do 63 "Hide and show the cursor." 64 (princ "Cursor visible:") 68 (princ "Cursor invisible:") 73 (princ "Cursor visible:") 80 "Switch to and back from the alternate screen buffer." 81 (princ "Normal screen buffer. ") 84 (save-cursor-position) 85 (use-alternate-screen-buffer) 87 (princ "Alternate screen buffer.") 90 (use-normal-screen-buffer) 91 (restore-cursor-position) 92 (princ "Back to Normal screen buffer.") 98 "Set individual termios flags to enable raw and disable echo mode. 100 Enabling raw mode allows read-char to return immediately after a key is pressed. 102 In the default cooked mode, the entry has to be confirmed by pressing enter." 103 (set-tty-mode t :ignbrk nil 122 (cursor-position 1 1) 124 (let ((a (read-char))) 125 (cursor-position 10 5) 129 (set-tty-mode t :echo t 141 "Use combination modes that consist of several individual flags. 143 Cooked and raw are opposite modes. Enabling cooked disbles raw and vice versa." 144 (set-tty-mode t :cooked nil) 146 (cursor-position 1 1) 148 (let ((a (read-char))) 149 (cursor-position 3 1) 152 (set-tty-mode t :raw nil)) 155 "Why doesnt calling the stty utility work?" 156 (uiop:run-program "stty raw -echo" :ignore-error-status t) 158 (cursor-position 1 1) 160 (let ((a (read-char))) 161 (cursor-position 2 1) 164 (uiop:run-program "stty -raw echo" :ignore-error-status t)) 167 "Query terminal size with ANSI escape sequences." 168 ;; Put the terminal into raw mode so we can read the "user input" 169 ;; of the reply char by char 170 ;; Turn off the echo or the sequence will be displayed 171 (set-tty-mode t :cooked nil :echo nil) 172 (save-cursor-position) 173 ;; Go to the bottom right corner of the terminal by attempting 174 ;; to go to some high value of row and column 175 (cursor-position 999 999) 177 ;; The terminal returns an escape sequence to the standard input 178 (device-status-report) 180 ;; The reply isnt immediately available, the terminal does need 181 ;; some time to answer 183 ;; The reply has to be read as if the user typed an escape sequence 184 (loop for i = (read-char-no-hang *standard-input* nil) 187 ;; Put the terminal back into its initial cooked state 188 (set-tty-mode t :raw nil :echo t) 189 (restore-cursor-position) 190 ;; Return the read sequence as a list of characters. 194 (with-input-from-string (in (format nil "~%~%"))