anchor.diff:    (setf (x-pos terminal) (saved-x terminal)
           (y-pos terminal) (saved-y terminal)))
   
  -(defun xterm-saw-escape (terminal char)
  -  "Saw escape byte."
  -  (case char
  -    (#\[ 'xterm-saw-bracket)
  -    (#\] 'xterm-saw-close-bracket)
  -    (#\( 'xterm-saw-paren)
  -    (#\) 'xterm-saw-close-paren)
  -    (#\> nil) ; DECKPNM
  -    (#\= nil) ; DECKPAM
  -    (#\M nil) ; Reverse index?
  -    ;; Save cursor position.
  -    (#\7 (save-cursor terminal)
  -         nil)
  -    ;; Restore cursor position.
  -    (#\8 (restore-cursor terminal)
  -         nil)
  -    (t (report-unknown-escape terminal) nil)))
  -
  -(defun xterm-saw-bracket (terminal char)
  -  "Saw '<Esc>[' and maybe some digits and semicolons."
  -  (cond ((eql char #\;)
  -         (cond ((slot-value terminal 'current-number)
  -                (push (slot-value terminal 'current-number) (slot-value terminal 'parameters))
  -                (setf (slot-value terminal 'current-number) nil))
  -               (t (push 0 (slot-value terminal 'parameters))))
  -         (return-from xterm-saw-bracket 'xterm-saw-bracket))
  -        ((digit-char-p char)
  -         (unless (slot-value terminal 'current-number)
  -           (setf (slot-value terminal 'current-number) 0))
  -         (setf (slot-value terminal 'current-number) (+ (* (slot-value terminal 'current-number) 10)
  -                                                        (- (char-code char) (char-code #\0))))
  -         (return-from xterm-saw-bracket 'xterm-saw-bracket))
  -        (t (when (slot-value terminal 'current-number)
  -             (push (slot-value terminal 'current-number) (slot-value terminal 'parameters))
  -             (setf (slot-value terminal 'current-number) nil))
  -           (case char
  -             (#\A
  -              (decf (y-pos terminal) (or (first (slot-value terminal 'parameters)) 1)))
  -             (#\B
  -              (incf (y-pos terminal) (or (first (slot-value terminal 'parameters)) 1)))
  -             (#\C
  -              (incf (x-pos terminal) (or (first (slot-value terminal 'parameters)) 1)))
  -             (#\D
  -              (decf (x-pos terminal) (or (first (slot-value terminal 'parameters)) 1)))
  -             (#\H
  -              (let* ((params (nreverse (slot-value terminal 'parameters)))
  -                     (row (or (first params) 1))
  -                     (column (or (second params) 1)))
  -                (setf (y-pos terminal) (1- row)
  -                      (x-pos terminal) (1- column))))
  -             (#\G
  -              (setf (x-pos terminal) (1- (or (first (slot-value terminal 'parameters)) 1))))
  -             (#\J
  -              (case (first (slot-value terminal 'parameters))
  -                ((0 nil)
  -                 ;; clear below
  -                 (erase terminal (x-pos terminal) (terminal-width terminal))
  -                 (clear terminal (1+ (y-pos terminal)) (terminal-height terminal)))
  -                (1 (clear terminal 0 (y-pos terminal))) ; clear above
  -                (2 (clear terminal 0 (terminal-height terminal)))
  -                (t (report-unknown-escape terminal))))
  -             (#\K
  -              (case (first (slot-value terminal 'parameters))
  -                ((0 nil) (erase terminal (x-pos terminal) (terminal-width terminal))) ; erase to right
  -                (1 (erase terminal 0 (x-pos terminal))) ; erase to left
  -                (2 (erase terminal 0 (terminal-width terminal))) ; erase all
  -                (t (report-unknown-escape terminal))))
  -             (#\L
  -              ;; Insert Pn lines, starting at the cursor. Lines move down.
  -              (when (<= (scroll-start terminal)
  -                        (y-pos terminal)
  -                        (1- (or (scroll-end terminal)
  -                                (terminal-height terminal))))
  -                (scroll-terminal terminal
  -                                 (y-pos terminal)
  -                                 (or (scroll-end terminal)
  -                                     (terminal-height terminal))
  -                                 (- (or (first (slot-value terminal 'parameters)) 1)))))
  -             (#\M
  -              ;; Delete Pn lines, starting at the cursor. Lines move up.
  -              (when (<= (scroll-start terminal)
  -                        (y-pos terminal)
  -                        (1- (or (scroll-end terminal)
  -                                (terminal-height terminal))))
  -                  (scroll-terminal terminal
  -                                   (y-pos terminal)
  -                                   (or (scroll-end terminal)
  -                                       (terminal-height terminal))
  -                                   (or (first (slot-value terminal 'parameters)) 1))))
  -             (#\d
  -              (setf (y-pos terminal) (1- (or (first (slot-value terminal 'parameters)) 1))))
  -             (#\m (set-character-attributes terminal (nreverse (slot-value terminal 'parameters))))
  -             (#\r ; set scroll region.
  -              (let ((params (nreverse (slot-value terminal 'parameters))))
  -                (setf (scroll-start terminal) (1- (or (first params) 1))
  -                      (scroll-end terminal) (when (second params)
  -                                              (1- (second params))))
  -                (format t "Scroll region: ~D ~D~%" (scroll-start terminal) (scroll-end terminal))))
  -             #+nil(#\h) ; set mode **
  -             #+nil(#\l) ; clear mode **
  -             (#\!
  -              (if (or (slot-value terminal 'parameters)
  -                      (slot-value terminal 'current-number))
  -                  (report-unknown-escape terminal)
  -                  (return-from xterm-saw-bracket 'xterm-saw-bracket-exclaim)))
  -             (#\?
  -              (if (or (slot-value terminal 'parameters)
  -                      (slot-value terminal 'current-number))
  -                  (report-unknown-escape terminal)
  -                  (return-from xterm-saw-bracket 'xterm-saw-bracket-question)))
  -             (t (report-unknown-escape terminal)))))
  -  nil)
  +(defun adjust-ansi-mode (terminal mode value)
  +  "Set an ANSI mode. '<Esc>[Pn;Pm...h' or '<Esc>[Pn;Pm...l'"
  +  (case mode
  +    (t (format t "Unsupported ANSI mode ~D.~%" mode))))
   
   (defun adjust-dec-private-mode (terminal mode value)
     "Set a DEC private mode. '<Esc>[?Pn;Pm...h' or '<Esc>[?Pn;Pm...l'"
  
positive.code:   (with-simple-restart (continue "Ignore this character.")
      (let ((new-state (funcall (terminal-state stream) stream char)))
        (cond (new-state
               (setf (terminal-state stream) new-state))
              (t (setf (terminal-state stream) 'xterm-initial
                       (slot-value stream 'current-number) nil
                       (slot-value stream 'parameters) '()
                       (slot-value stream 'escape-sequence) '()))))))
  
  (defvar *xterm-translations*
    (list (list (name-char "Up-Arrow")    '(#\Esc #\[ #\A))
  
negative.code:    (input :initarg :input)
     (queued-bytes :initarg :queued-bytes)
     (interrupt-character :initarg :interrupt-character :accessor interrupt-character)
     (state :initform 'xterm-ground :accessor terminal-state)
  
     (intermediate-characters :initform '())
     (parameters :initform (make-array 16 :initial-element nil))
     (n-parameters :initform 0)
     (escape-sequence :initform '())
     (osc-buffer :initform (make-array 100 :fill-pointer 0 :element-type 'character))
  
     (width :reader terminal-width)
     (height :reader terminal-height)
     (x-pos :initform 0 :accessor x-pos)
  