anchor.diff:    (:default-initargs
      :interrupt-character nil
      :queued-bytes '()
  -   :state nil
      :x 0 :y 0))
   
   (defmethod initialize-instance :after ((term xterm-terminal) &key width height)
  
positive.code:    (input :initarg :input)
     (queued-bytes :initarg :queued-bytes)
     (interrupt-character :initarg :interrupt-character :accessor interrupt-character)
     (state :initarg :state :accessor terminal-state)
     (current-number)
     (parameters)
     (escape-sequence)
     (width :reader terminal-width)
     (height :reader terminal-height)
     (x-pos :initform 0 :accessor x-pos)
  
negative.code:                           #xFF000000 (terminal-framebuffer term)
                            (+ (* (y-pos term) 16) (y-offset term)) (+ (* left 8) (x-offset term)))))
  
  (defun xterm-initial (terminal byte)
    "Initial state."
    (case (code-char byte)
      (#\Escape
       (return-from xterm-initial
         'xterm-saw-escape))
      (#\Cr
       (setf (x-pos terminal) 0))
      (#\Lf
       (incf (y-pos terminal)))
      (#\Bs
       (decf (x-pos terminal)))
      (t (write-terminal terminal (code-char byte))))
    nil)
  
  (defun xterm-saw-escape (terminal byte)
    "Saw escape byte."
    (case (code-char byte)
      (#\[ 'xterm-saw-bracket)
      (#\( 'xterm-saw-paren)
      (#\> nil) ; ???
      (#\= nil) ; ???
      (#\M nil) ; Reverse index?
      (t (report-unknown-escape terminal) nil)))
  
  (defun xterm-saw-bracket (terminal byte)
    "Saw '<Esc>[' and maybe some digits and semicolons."
    (cond ((eql (code-char byte) #\;)
           (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 (code-char byte))
           (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)
                                                          (- byte (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 (code-char byte)
               (#\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 terminal 0 (y-pos terminal))) ; clear above
                  (1 (clear terminal (y-pos terminal) (terminal-height terminal))) ; clear below
                  (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))))
               (#\d
                (setf (y-pos terminal) (1- (or (first (slot-value terminal 'parameters)) 1))))
               (#\m) ; character attributes **
               (#\r) ; set scroll region. **
               (#\h) ; set mode **
               (#\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-question)))
               (t (report-unknown-escape terminal)))))
    nil)
  
  (defun xterm-saw-bracket-question (terminal byte)
    "Saw '<Esc>[?'"
    (cond ((eql (code-char byte) #\;)
           (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 (code-char byte))
           (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)
                                                        (- byte (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 (code-char byte)
               (#\h) ; DEC private mode set **
               (#\l) ; DEC private mode clear **
               (t (report-unknown-escape terminal)))
             nil)))
  
  (defun xterm-saw-paren (terminal byte)
    "Saw '<Esc>(', expecting a character set identifier."
    nil)
  
  (defmethod sys.int::stream-write-byte (byte (stream xterm-terminal))
    (push byte (slot-value stream 'escape-sequence))
    (let ((new-state (funcall (terminal-state stream) stream byte)))
      (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))
  