anchor.diff:     (%xterm :initarg :xterm :reader xterm)
      (%terminal-type :initarg :terminal-type :reader terminal-type)
      (%connection :initarg :connection :accessor connection)
  -   (%receive-thread :initarg :receive-thread :accessor receive-thread)
  -   (%do-window-size-updates :initarg :do-window-size-updates :accessor do-window-size-updates))
  +   (%do-window-size-updates :initarg :do-window-size-updates :accessor do-window-size-updates)
  +   (%last-was-cr :initform nil :accessor last-was-cr))
     (:default-initargs :connection nil))
  -
  -(defclass server-disconnect-event ()
  -  ())
   
   (defun compute-telnet-window-size (font cwidth cheight)
     ;; Make a fake frame to get the frame size.
  
positive.code:                                          (when (eql ch (code-char +command-iac+))
                                             (write-byte +command-iac+ (connection telnet)))
                                           (write-byte (char-code ch) (connection telnet))))))
  
  (defmethod dispatch-event (telnet (event server-disconnect-event))
    (setf (connection telnet) nil)
    (telnet-write-string telnet (format nil "~%Disconnected from server")))
  
  (defmethod dispatch-event (app (event mezzano.gui.compositor:resize-request-event))
    (let ((old-width (mezzano.gui.compositor:width (window app)))
  
negative.code:               (unwind-protect
                     (progn
                       (setf server (find-server telnet server))
                       (setf (connection telnet) (mezzano.network.tcp:tcp-stream-connect server port :element-type '(unsigned-byte 8)))
                       ;; Announce capabilities.
                       (write-sequence (vector-ub8 +command-iac+ +command-do+ +option-suppress-go-ahead+
                                                   +command-iac+ +command-will+ +option-window-size+)
                                       (connection telnet))
                       (setf (mezzano.gui.widgets:frame-title frame) (format nil "Telnet - ~A:~D" server port))
                       (mezzano.gui.widgets:draw-frame frame)
                       ;; Main interaction loop, when connected to the server.
                       (loop
                          (when (not (connection telnet))
                            (return))
                          (mezzano.sync:wait-for-objects fifo (connection telnet))
                          (loop
                             for msg = (mezzano.supervisor:fifo-pop fifo nil)
                             while msg
                             do (dispatch-event telnet msg))
                          (loop
                             for byte = (sys.int::read-byte-no-hang (connection telnet) nil :eof)
                             while byte
                             do (cond ((eql byte :eof)
                                       ;; Server disconnected
                                       (setf (connection telnet) nil)
                                       (telnet-write-string telnet (format nil "~%Disconnected from server"))
                                       (return))
                                      (t
                                       (telnet-receive-byte telnet byte)))))
                       ;; Post-connection interaction loop. Just processing compositor events.
                       (loop
                          (dispatch-event telnet (mezzano.supervisor:fifo-pop fifo))))
                  (when (connection telnet)
  