bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31690: 26.1; term.el doesn't move cursor down into last row


From: Noam Postavsky
Subject: bug#31690: 26.1; term.el doesn't move cursor down into last row
Date: Sat, 02 Jun 2018 17:03:56 -0400

Tags: patch

GNU nano fails to display the bottom line correctly in M-x term, as
reported in [1].  This is due an off by one error in the handling of the
down cursor escape sequence (\e[B).  Here's a patch:

>From a7c394806d3b97f65c4b3687ee67908d8a1eb7a9 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <address@hidden>
Date: Sat, 2 Jun 2018 15:57:33 -0400
Subject: [PATCH] Fix term.el cursor movement at bottom margin

* lisp/term.el (term-handle-ansi-escape) <\E[B cud>: Allow moving the
cursor to the bottom margin line, rather than stopping one line
before.
---
 lisp/term.el            |  7 +++----
 test/lisp/term-tests.el | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/term.el b/lisp/term.el
index 75c2779783..c36224566b 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -3386,11 +3386,10 @@ term-handle-ansi-escape
    ;; \E[B - cursor down (terminfo: cud)
    ((eq char ?B)
     (let ((tcr (term-current-row)))
-      (unless (= tcr (1- term-scroll-end))
+      (unless (>= tcr term-scroll-end)
        (term-down
-        (if (> (+ tcr term-terminal-parameter) term-scroll-end)
-            (- term-scroll-end 1 tcr)
-          (max 1 term-terminal-parameter)) t))))
+         (min (- term-scroll-end tcr) (max 1 term-terminal-parameter))
+         t))))
    ;; \E[C - cursor right (terminfo: cuf, cuf1)
    ((eq char ?C)
     (term-move-columns
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 234dfa1f0d..7fd8d1293d 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -124,6 +124,27 @@ term-test-screen-from-input
                     40 12 (list "\eAnSiTc /f" "oo/\n") 'default-directory)
                    "/foo/"))))
 
+(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
-- 
2.11.0

[1]: 
https://emacs.stackexchange.com/questions/41796/nano-not-displaying-correctly-in-term-and-ansi-term

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2018-04-09 built on zebian
Repository revision: 24ba63314f29fdffa9cfe012927e5efd744c138d
Windowing system distributor 'The X.Org Foundation', version 11.0.11902000
System Description:     Debian GNU/Linux 9.3 (stretch)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]