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:             (restore-cursor terminal))))
      (t (format t "Unsupported DEC private mode ~D.~%" mode))))
  
  (defun xterm-saw-bracket-exclaim (terminal char)
    "Saw '<Esc>[!'"
    (case char
      (#\p ; DECSTR.
       (soft-reset terminal))
      (t (report-unknown-escape terminal)))
    nil)
  
  (defun xterm-saw-bracket-question (terminal char)
    "Saw '<Esc>[?'"
    (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))))
           'xterm-saw-bracket-question)
          ((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))))
           'xterm-saw-bracket-question)
          (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
               (#\h
                (dolist (p (nreverse (slot-value terminal 'parameters)))
                  (adjust-dec-private-mode terminal p t)))
               (#\l
                (dolist (p (nreverse (slot-value terminal 'parameters)))
                  (adjust-dec-private-mode terminal p nil)))
               (t (report-unknown-escape terminal)))
             nil)))
  
  (defun xterm-saw-close-bracket (terminal char)
    "Saw '<Esc>]'/OSC 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-close-bracket 'xterm-saw-close-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-close-bracket 'xterm-saw-close-bracket))
          (t (report-unknown-escape terminal)))
    nil)
  
  (defun xterm-saw-paren (terminal char)
    "Saw '<Esc>(', expecting a character set identifier."
    ;; Set G0 character set.
    (case char
      (#\B (setf (charset terminal) :us-ascii))
      (#\0 (setf (charset terminal) :dec))
      (t (setf (charset terminal) :us-ascii)
         (report-unknown-escape terminal)))
    nil)
  
  (defun xterm-saw-close-paren (terminal char)
    "Saw '<Esc>)', expecting a character set identifier."
    ;; Set G1 character set.
    (case char
      (#\B #+nil(setf (charset terminal) :us-ascii))
      (#\0 #+nil(setf (charset terminal) :dec))
      (t #+nil(setf (charset terminal) :us-ascii)
         (report-unknown-escape terminal)))
    nil)
  
  (defun utf-8-code-point-length (code-point)
    "Return the number of bytes required to encode CODE-POINT or NIL if it can't be encoded."
  
negative.code:   (with-simple-restart (continue "Ignore this character.")
      (let ((new-state (funcall (terminal-state stream) stream char)))
        (cond (new-state
               (when (eql new-state 'xterm-ground)
                 (setf (slot-value stream 'escape-sequence) '()))
               (setf (terminal-state stream) new-state))
              (t (setf (terminal-state stream) 'xterm-ground))))))
  
  (defvar *xterm-translations*
    (list (list (name-char "Up-Arrow")    '(#\Esc #\[ #\A))
  