;; If the amount to move is before scroll start, move
;; to scroll start.
(- term-scroll-start tcr)
- (if (>= term-terminal-parameter tcr)
+ (if (>= scroll-amount tcr)
(- tcr)
- (- (max 1 term-terminal-parameter)))) t)))
+ (- (max 1 scroll-amount))))
+ t)))
;; \E[B - cursor down (terminfo: cud)
((eq char ?B)
- (let ((tcr (term-current-row)))
+ (let ((tcr (term-current-row))
+ (scroll-amount (car params)))
- (unless (= tcr (1- term-scroll-end))
+ (unless (>= tcr term-scroll-end)
(term-down
- (if (> (+ tcr scroll-amount) term-scroll-end)
- (- term-scroll-end 1 tcr)
- (max 1 scroll-amount))
- (min (- term-scroll-end tcr) (max 1 term-terminal-parameter))
++ (min (- term-scroll-end tcr) (max 1 scroll-amount))
t))))
;; \E[C - cursor right (terminfo: cuf, cuf1)
((eq char ?C)
40 12 (list "\eAnSiTc /f" "oo/\n") 'default-directory)
"/foo/"))))
-
+(ert-deftest term-line-wrapping-then-motion ()
+ "Make sure we reset the line-wrapping state after moving cursor.
+A real-life example is the default zsh prompt which writes spaces
+to the end of line (triggering line-wrapping state), and then
+sends a carriage return followed by another space to overwrite
+the first character of the line."
+ (let* ((width 10)
+ (strs (list "x" (make-string (1- width) ?_)
+ "\r_")))
+ (should (equal (term-test-screen-from-input width 12 strs)
+ (make-string width ?_)))))
+
+ (ert-deftest term-to-margin ()
+ "Test cursor movement at the scroll margin.
+ This is a reduced example from GNU nano's initial screen."
+ (let* ((width 10)
+ (x (make-string width ?x))
+ (y (make-string width ?y)))
+ (should (equal (term-test-screen-from-input
+ width 3
+ `("\e[1;3r" ; Setup 3 line scrolling region.
+ "\e[2;1H" ; Move to 2nd last line.
+ ,x ; Fill with 'x'.
+ "\r\e[1B" ; Next line.
+ ,y)) ; Fill with 'y'.
+ (concat "\n" x "\n" y)))
+ ;; Same idea, but moving upwards.
+ (should (equal (term-test-screen-from-input
+ width 3
+ `("\e[1;3r" "\e[2;1H" ,x "\r\e[1A" ,y))
+ (concat y "\n" x)))))
+
(provide 'term-tests)
;;; term-tests.el ends here