Only send show/hide cursor commands when needed

This commit is contained in:
John Lorentzson 2025-07-31 14:45:44 +02:00
parent d7643b63c8
commit 38b42a3e9a

View file

@ -82,6 +82,21 @@ serial connection the editor normally runs under.")
(defmethod stream-finish-output ((stream hybrid-stream))
(finish-output (output-stream stream)))
(defclass terminal-stream (hybrid-stream)
((%cursor-visibility :accessor cursor-visibility :initform 0)))
(defmethod terminal-hide-cursor ((stream terminal-stream))
(when (zerop (cursor-visibility stream))
(write-byte #x1B *eio*)
(write-string "[?25l" *eio*))
(decf (cursor-visibility stream)))
(defmethod terminal-show-cursor ((stream terminal-stream))
(incf (cursor-visibility stream))
(when (zerop (cursor-visibility stream))
(write-byte #x1B *eio*)
(write-string "[?25h" *eio*)))
(defun open-terminal (path)
@ -92,8 +107,8 @@ serial connection the editor normally runs under.")
:element-type '(unsigned-byte 8)
:if-exists :overwrite))
(handler-case
(make-instance 'hybrid-stream :input-stream input-stream
:output-stream output-stream)
(make-instance 'terminal-stream :input-stream input-stream
:output-stream output-stream)
(error ()
(close input-stream)
(close output-stream)))))
@ -192,12 +207,10 @@ serial connection the editor normally runs under.")
(restore-cursor))
(defun hide-cursor ()
(write-byte #x1B *eio*)
(write-string "[?25l" *eio*))
(terminal-hide-cursor *eio*))
(defun show-cursor ()
(write-byte #x1B *eio*)
(write-string "[?25h" *eio*))
(terminal-show-cursor *eio*))
(defun invert-text ()
(write-byte #x1B *eio*)