diff --git a/src/backend/simple.lisp b/src/backend/simple.lisp index 8923771..6b7e939 100644 --- a/src/backend/simple.lisp +++ b/src/backend/simple.lisp @@ -21,6 +21,9 @@ (defmethod resume-backend ((b simple-backend)) (values)) +(defmethod end-sync ((b simple-backend)) + (finish-output (backend-output-stream b))) + (defmethod backend-size ((b simple-backend)) ;; Try ioctl on fd 0 (stdin), then stdout, then /dev/tty, then 80x24. ;; Use multiple-value-bind/values to preserve both cols and rows @@ -79,8 +82,18 @@ (defmethod draw-text ((b simple-backend) x y string fg bg &key bold italic underline reverse dim blink &allow-other-keys) - (declare (ignore x y fg bg bold italic underline reverse dim blink)) - (backend-write b string)) + (let* ((style-reset (format nil "~C[22;23;24;25;27m" #\Esc)) + (parts (list (cursor-move-escape x y) + (sgr-fg fg) (sgr-bg bg) + (when bold (sgr-attr :bold)) + (when italic (sgr-attr :italic)) + (when underline (sgr-attr :underline)) + (when reverse (sgr-attr :reverse)) + (when dim (sgr-attr :dim)) + (when blink (sgr-attr :blink)) + string + style-reset))) + (backend-write b (apply #'concatenate 'string parts)))) (defun %simple-border-char (pos) "Return ASCII border character at POS. @@ -142,19 +155,22 @@ POS is :top-left, :top-right, :bottom-left, :bottom-right, (defmethod draw-rect ((b simple-backend) x y width height &key bg) - (declare (ignore x y width height bg)) - ;; On simple backend, background fill is a no-op - (values)) + (let* ((bg-esc (sgr-bg bg)) + (style-reset (format nil "~C[22;23;24;25;27m" #\Esc)) + (line (concatenate 'string + bg-esc + (make-string width :initial-element #\Space) + style-reset (string #\Newline)))) + (loop :for row :from 0 :below height :do + (backend-write b (cursor-move-escape x (+ y row))) + (backend-write b line)))) (defmethod draw-link ((b simple-backend) x y string url &key fg bg) - (declare (ignore url fg bg)) - (draw-text b x y string nil nil)) + (declare (ignore url)) + (draw-text b x y string fg bg)) (defmethod draw-ellipsis ((b simple-backend) x y width &key fg bg) - (declare (ignore width fg bg)) - ;; Position using newlines+spaces (simple-backend pattern) - (dotimes (row y) (backend-write b (string #\Newline))) - (backend-write b (make-string x :initial-element #\Space)) - (backend-write b "...")) + (declare (ignore width)) + (draw-text b x y "..." fg bg))