anchor.diff:  ;; for mintty
   ;; get cur-x for moving cursor position properly
   (defun get-cur-x (view x y &key (modeline nil))
  -  (unless (slot-value *windows-term-setting* 'cur-char-width)
  +  (unless (and (not (slot-value *windows-term-setting* 'cur-mov-by-pos))
  +               (slot-value *windows-term-setting* 'disp-char-width)
  +               (slot-value *windows-term-setting* 'pos-char-width)
  +               (slot-value *windows-term-setting* 'cur-char-width))
       (return-from get-cur-x (get-pos-x view x y :modeline modeline)))
  -  (let* ((disp-char-width-fn (disp-char-width-func))
  -         (pos-char-width-fn  (pos-char-width-func))
  -         (cur-char-width-fn  (cur-char-width-func))
  -         (start-x (ncurses-view-x view))
  +  (let* ((start-x (ncurses-view-x view))
            (disp-x0 (+ x start-x))
            (disp-x  0)
            (pos-x   0)
  
positive.code:      (make-instance 'windows-term-setting
                      :disp-char-width t
                      :pos-char-width  t
                      :cur-char-width  t))
      (:conemu
       (make-instance 'windows-term-setting
                      :disp-char-width t
                      :pos-char-width  t
                      :cur-char-width  nil))
      (t
       (make-instance 'windows-term-setting
                      :disp-char-width nil
                      :pos-char-width  nil
                      :cur-char-width  nil))))
  (defun disp-char-width-func ()
    (let ((fn (slot-value *windows-term-setting* 'disp-char-width)))
      (if (functionp fn)
          fn
          (lambda (code)
            ;; check zero-width-space character (#\u200b)
            (if (= code #x200b)
                0
                (if (lem-base:wide-char-p (code-char code)) 2 1))))))
  (defun pos-char-width-func ()
    (let ((fn (slot-value *windows-term-setting* 'pos-char-width)))
      (if (functionp fn)
          fn
          (lambda (code)
            ;; check utf-16 surrogate pair characters
            (if (< code #x10000) 1 2)))))
  (defun cur-char-width-func ()
    (let ((fn (slot-value *windows-term-setting* 'cur-char-width)))
      (if (functionp fn)
          fn
          (lambda (code)
            ;; check zero-width-space character (#\u200b)
            (if (= code #x200b)
                0
                (if (lem-base:wide-char-p (code-char code)) 2 1))))))
  
  ;; load windows dll
  ;;  (we load winmm.dll with a full path because it isn't listed in
  
negative.code:           (lem:window-y      window)
            (lem:window-width  window)
            (lem:window-height window)))
  ;; for mintty and ConEmu
  ;; get mouse disp-x for pointing wide characters properly
  (defun mouse-get-disp-x (view x y)
    (cond
      ((and (not (slot-value *windows-term-setting* 'cur-mov-by-pos))
            (slot-value *windows-term-setting* 'disp-char-width)
            (slot-value *windows-term-setting* 'pos-char-width)
            (slot-value *windows-term-setting* 'cur-char-width))
       ;; for mintty
       (let ((disp-x 0)
             (pos-x  0)
             (pos-y  y)
             (cur-x  0))
         (loop :while (< cur-x x)
            :for code := (get-charcode-from-scrwin view pos-x pos-y)
            :until (= code charms/ll:ERR)
            :do (incf disp-x (disp-char-width *windows-term-setting* code))
                (incf pos-x  (pos-char-width  *windows-term-setting* code))
                (incf cur-x  (cur-char-width  *windows-term-setting* code)))
         disp-x))
      ((and (slot-value *windows-term-setting* 'cur-mov-by-pos)
            (slot-value *windows-term-setting* 'disp-char-width)
            (slot-value *windows-term-setting* 'pos-char-width))
       ;; for ConEmu
       (let* ((disp-x 0)
              (pos-x  0)
              (pos-y  y))
         (loop :while (< pos-x x)
            :for code := (get-charcode-from-scrwin view pos-x pos-y)
            :until (= code charms/ll:ERR)
            :do (incf disp-x (disp-char-width *windows-term-setting* code))
                (incf pos-x  (pos-char-width  *windows-term-setting* code)))
         disp-x))
      (t x)))
  ;; for ConEmu
  ;; get mouse cur-x for horizontal dragging window
  (defun mouse-get-cur-x (view x y)
    (cond
      ((and (slot-value *windows-term-setting* 'cur-mov-by-pos)
            (slot-value *windows-term-setting* 'pos-char-width)
            (slot-value *windows-term-setting* 'cur-char-width))
       (let* ((pos-x 0)
              (pos-y y)
              (cur-x 0))
         (loop :while (< pos-x x)
            :for code := (get-charcode-from-scrwin view pos-x pos-y)
            :until (= code charms/ll:ERR)
            :do (incf pos-x (pos-char-width *windows-term-setting* code))
                (incf cur-x (cur-char-width *windows-term-setting* code)))
         cur-x))
      ((and (slot-value *windows-term-setting* 'cur-mov-by-pos)
            (slot-value *windows-term-setting* 'disp-char-width)
            (slot-value *windows-term-setting* 'pos-char-width))
       (mouse-get-disp-x view x y))
      (t x)))
  (defun mouse-move-to-cursor (window x y)
    (lem:move-point (lem:current-point) (lem::window-view-point window))
    (lem:move-to-next-virtual-line (lem:current-point) y)
    (lem:move-to-virtual-line-column (lem:current-point) x))
  (defun mouse-event-proc (bstate x1 y1)
    (lambda ()
      ;; workaround for cursor position problem
      (let ((disp-x (mouse-get-disp-x (lem:window-view (lem:current-window)) x1 y1))
            (cur-x  (mouse-get-cur-x  (lem:window-view (lem:current-window)) x1 y1)))
        ;; process mouse event
        (cond
          ;; button1 down
          ((logtest bstate (logior charms/ll:BUTTON1_PRESSED
                                   charms/ll:BUTTON1_CLICKED
                                   charms/ll:BUTTON1_DOUBLE_CLICKED
                                   charms/ll:BUTTON1_TRIPLE_CLICKED))
           (let ((press (logtest bstate charms/ll:BUTTON1_PRESSED)))
             (find-if
              (lambda(o)
                (multiple-value-bind (x y w h) (mouse-get-window-rect o)
                  (cond
                    ;; vertical dragging window
                    ((and press (= y1 (- y 1)) (<= x disp-x (+ x w -1)))
                     (setf *dragging-window* (list o 'y))
                     t)
                    ;; horizontal dragging window
                    ((and press (= disp-x (- x 1)) (<= y y1 (+ y h -2)))
                     (setf *dragging-window* (list o 'x))
                     t)
                    ;; move cursor
                    ((and (<= x disp-x (+ x w -1)) (<= y y1 (+ y h -2)))
                     (setf (lem:current-window) o)
                     (mouse-move-to-cursor o (- disp-x x) (- y1 y))
                     (lem:redraw-display)
                     t)
                    (t nil))))
              (lem:window-list))))
          ;; button1 up
          ((logtest bstate charms/ll:BUTTON1_RELEASED)
           (let ((o (first *dragging-window*)))
             (when (windowp o)
               (multiple-value-bind (x y w h) (mouse-get-window-rect o)
                 (setf (lem:current-window) o)
                 (cond
                   ;; vertical dragging window
                   ((eq (second *dragging-window*) 'y)
                    (let ((vy (- (- (lem:window-y o) 1) y1)))
                      ;; this check is incomplete if 3 or more divisions exist
                      (when (and (>= y1       *min-lines*)
                                 (>= (+ h vy) *min-lines*))
                        (lem:grow-window vy)
                        (lem:redraw-display))))
                   ;; horizontal dragging window
                   (t
                    (let ((vx (- (- (lem:window-x o) 1) cur-x)))
                      ;; this check is incomplete if 3 or more divisions exist
                      (when (and (>= cur-x    *min-cols*)
                                 (>= (+ w vx) *min-cols*))
                        (lem:grow-window-horizontally vx)
                        (lem:redraw-display))))
                   )))
             (when o
               (setf *dragging-window*
                     (list nil (list cur-x y1) *dragging-window*)))))
          ;; wheel up
          ((logtest bstate charms/ll:BUTTON4_PRESSED)
           (lem:scroll-up 3)
           (lem:redraw-display))
          ;; wheel down
          ((logtest bstate charms/ll:BUTTON5_PRESSED)
           (lem:scroll-down 3)
           (lem:redraw-display))
          ))))
  
  ;; deal with utf-16 surrogate pair characters (input)
  (defun get-key (code)
  