Compare commits

..

No commits in common. "78487f1c24becbdee05b046128b5fdae14662cc0" and "c2fde9fdd09088671e399ac9afc9b61b5bc0661d" have entirely different histories.

View file

@ -11,9 +11,6 @@
(require '#:sb-posix)
(defvar *eio*)
(defparameter *slow-mode-p* nil
"Slows down the sending of characters to the terminal to simulate the slow
serial connection the editor normally runs under.")
(defclass hybrid-stream (fundamental-stream)
((%input-stream :accessor input-stream :initarg :input-stream)
@ -32,10 +29,7 @@ serial connection the editor normally runs under.")
(sb-posix:file-descriptor (output-stream stream)))
(defmethod stream-write-byte ((stream hybrid-stream) integer)
(write-byte integer (output-stream stream))
(when *slow-mode-p*
(force-output stream)
(sleep 10/9600)))
(write-byte integer (output-stream stream)))
(defmethod stream-write-char ((stream hybrid-stream) character)
(if (char= character #\Newline)
@ -145,18 +139,6 @@ serial connection the editor normally runs under.")
(write-char #\K *eio*)
(force-output *eio*))
(defun set-scrolling-region (&optional top bottom)
(assert (or (and (typep top 'integer) (typep bottom 'integer))
(and (null top) (null bottom))))
(cond ((and top bottom)
;; Set the region
(write-byte #x1B *eio*)
(format *eio* "[~D;~Dr" top bottom))
(t
;; Reset the region to fullscreen
(write-byte #x1B *eio*)
(format *eio* "[1;24r"))))
(defun scroll-screen-down (&optional (amount 1))
(write-byte #x1B *eio*)
(write-char #\[ *eio*)
@ -169,22 +151,6 @@ serial connection the editor normally runs under.")
(format *eio* "~D" amount)
(write-char #\S *eio*))
(defun hide-cursor ()
(write-byte #x1B *eio*)
(write-string "[?25l" *eio*))
(defun show-cursor ()
(write-byte #x1B *eio*)
(write-string "[?25h" *eio*))
(defun invert-text ()
(write-byte #x1B *eio*)
(write-string "[7m" *eio*))
(defun reset-text-attributes ()
(write-byte #x1B *eio*)
(write-string "[m" *eio*))
(defparameter +screen-width+ 80)
@ -315,9 +281,7 @@ serial connection the editor normally runs under.")
(incf (fill-pointer (line-content line)))
(replace (line-content line) to-shove
:start1 (1+ column))
(setf (char (line-content line) column) character))))
(when (line-in-view line (current-view *editor*))
(redisplay-line line :start column)))
(setf (char (line-content line) column) character)))))
(defmethod delete-character-in-line ((line line) column)
(unless (< column (fill-pointer (line-content line)))
@ -367,27 +331,23 @@ serial connection the editor normally runs under.")
(cursor-column (cursor *editor*)) start)
(update-buffer-cursor (current-buffer *editor*))))))
(defmethod redisplay-line ((line line) &key (start 0))
(defmethod redisplay-line ((line line))
;; TODO: save the cursor position
(with-editor-accessors *editor* (:current-line current
:current-buffer buffer)
(cond
((= start (1- (line-length line)))
(let ((char-pos (1- (fill-pointer (line-content line)))))
(move-cursor (view-line-number (buffer-view buffer) line) char-pos)
(write-char (aref (line-content line) char-pos) *eio*)
(update-buffer-cursor buffer)))
(t
(hide-cursor)
(move-cursor (view-line-number (buffer-view buffer) line) start)
(write-byte #x1B *eio*)
(write-char #\[ *eio*)
(write-char #\K *eio*)
(write-string (line-content line) *eio* :start start)
(update-buffer-cursor buffer)
(show-cursor))))
(move-cursor (view-line-number (buffer-view buffer) line) 0)
(write-char #\Return *eio*)
(write-byte #x1B *eio*)
(write-char #\[ *eio*)
(write-char #\K *eio*)
(write-string (line-content line) *eio*)
(update-buffer-cursor buffer))
(force-output *eio*))
(defun save-cursor ())
(defun restore-cursor ())
(defclass buffer ()
@ -443,30 +403,17 @@ Additionally ensures correct line numbers on the way, as a bonus."
(line-number (cursor-line *editor*))
(cursor-column *editor*)))
(defparameter *status-line-position* 24
"The line at which the status line should be drawn.")
(defvar *old-status-line-string* nil)
(defun redisplay-status-line (&key completely-p)
(when completely-p
(setf *old-status-line-string* nil))
(when (null *old-status-line-string*)
(setf *old-status-line-string* (status-line-string)))
(let* ((new-status (status-line-string))
(old-status *old-status-line-string*)
(difference-start (or (mismatch new-status old-status) 0))
(difference-end (or (mismatch new-status old-status :from-end t) nil)))
(hide-cursor)
(move-cursor *status-line-position* difference-start)
(invert-text)
(write-string (subseq (status-line-string)
difference-start
difference-end)
*eio*)
(reset-text-attributes)
(update-buffer-cursor (current-buffer *editor*))
(setf *old-status-line-string* new-status)
(show-cursor)))
(defun redisplay-status-line ()
(move-cursor 24 0)
(write-byte #x1B *eio*)
(write-char #\[ *eio*)
(write-char #\7 *eio*)
(write-char #\m *eio*)
(write-string (status-line-string) *eio*)
(write-byte #x1B *eio*)
(write-char #\[ *eio*)
(write-char #\m *eio*)
(update-buffer-cursor (current-buffer *editor*)))
@ -504,9 +451,6 @@ Additionally ensures correct line numbers on the way, as a bonus."
:when (eql line view-line)
:return number))
(defmethod line-in-view ((line line) (view buffer-view))
(not (null (view-line-number view line))))
(defmethod redisplay-view ((view buffer-view))
(clear-screen)
(do-view-lines (line number) view
@ -541,7 +485,7 @@ Additionally ensures correct line numbers on the way, as a bonus."
(bottom-line view) (next-line (bottom-line view)))
(unless (null (bottom-line view))
(redisplay-view-from-line view (bottom-line view)))
(redisplay-status-line :completely-p t))
(redisplay-status-line))
(defmethod scroll-view-up ((view buffer-view))
(scroll-screen-down 1) ; view goes up, screen contents go down
@ -551,7 +495,7 @@ Additionally ensures correct line numbers on the way, as a bonus."
(bottom-line view)
(prev-line (bottom-line view)))
(redisplay-line (top-line view))
(redisplay-status-line :completely-p t))
(redisplay-status-line))
(defmethod current-view ((obj editor))
(buffer-view (current-buffer obj)))
@ -569,7 +513,8 @@ Additionally ensures correct line numbers on the way, as a bonus."
(progn
(insert-character-into-line line column char)
(incf column))
(feep))))
(feep))
(redisplay-line line)))
(defun com-forward-delete ()
;; TODO: Check for end of line
@ -592,22 +537,11 @@ Additionally ensures correct line numbers on the way, as a bonus."
(defun com-newline ()
(with-editor-accessors *editor* (:current-column column
:current-line line)
(let* ((old-line line)
(new-line (new-line-at line column))
(in-view-p (line-in-view new-line (current-view *editor*))))
(ensure-correct-line-number new-line)
(com-next-line)
(com-beginning-of-line)
(when in-view-p
(set-scrolling-region (view-line-number (current-view *editor*)
new-line)
(1- *status-line-position*))
(scroll-screen-down)
(set-scrolling-region))
(when (line-in-view old-line (current-view *editor*))
(redisplay-line old-line :start column))
(when in-view-p
(redisplay-line new-line)))))
(ensure-correct-line-number (new-line-at line column))
(redisplay-view-from-line (current-view *editor*) line)
(com-next-line)
(com-beginning-of-line)
(redisplay-line line)))
(defun com-beginning-of-line ()
(with-editor-accessors *editor* (:current-column column
@ -677,8 +611,7 @@ Additionally ensures correct line numbers on the way, as a bonus."
(redisplay-view (buffer-view (current-buffer *editor*))))
(defun com-refresh-screen ()
(redisplay-view (buffer-view (current-buffer *editor*)))
(redisplay-status-line :completely-p t))
(redisplay-view (buffer-view (current-buffer *editor*))))