Skip to content

Commit

Permalink
fix: Allow adjusting terminal window of TRAMP processes.
Browse files Browse the repository at this point in the history
Before this change, the terminal window of TRAMP processes was never
adjusted, which resulted in badly-sized output.

This change resets the adjust-window-size-function set to ignore by
TRAMP to its default function and tests its effect in a remote shell.
  • Loading branch information
szermatt committed Oct 8, 2024
1 parent 73e8166 commit a4c6f23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mistty-term.el
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,12 @@ This function returns the newly-created buffer."
(setq-local term-height height)
(setq-local term-command-function #'mistty--term-command-hook)
(mistty-term--exec program args)
(set-process-window-size (get-buffer-process term-buffer) height width)
(let ((proc (get-buffer-process term-buffer)))
;; TRAMP sets adjust-window-size-function to #'ignore, which
;; prevents normal terminal resizing from working. This turns
;; it on again.
(process-put proc 'adjust-window-size-function nil)
(set-process-window-size proc height width))
(setq-local term-raw-map local-map)
(term-char-mode)
(advice-add 'move-to-column :around #'mistty--around-move-to-column)
Expand Down
1 change: 1 addition & 0 deletions mistty.el
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,7 @@ only spaces with ==\'mistty-skip t between them."
window-adjust-process-window-size-function))
(size (funcall adjust-func mistty-proc
(get-buffer-window-list mistty-work-buffer nil t))))
(mistty-log "set-process-window-size %s" size)
(when size
(let ((width (- (car size) left-margin-width))
(height (cdr size)))
Expand Down
20 changes: 20 additions & 0 deletions test/mistty-tramp-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,23 @@
(mistty--send-string mistty-proc "printf '\\032//home\\nok\\n'")
(should (equal "ok" (mistty-send-and-capture-command-output)))
(should (equal (concat sg-prefix "/home/") default-directory)))))

(ert-deftest mistty-tramp-test-window-size ()
(let* ((sg-prefix (mistty-test-sg-prefix))
(home (file-name-directory "/"))
(default-directory (concat sg-prefix home)))
(mistty-with-test-buffer (:selected t)
(let ((win (selected-window))
cols-before cols-after)
(mistty-send-text "tput cols")
(setq cols-before (string-to-number (mistty-send-and-capture-command-output)))

(split-window-horizontally nil win)
(mistty--window-size-change win)

;; This makes sure the terminal is told about the window size
;; change.
(mistty-send-text "tput cols")
(setq cols-after (string-to-number (mistty-send-and-capture-command-output)))
(should-not (equal cols-before cols-after))
(should (< cols-after cols-before))))))

0 comments on commit a4c6f23

Please sign in to comment.