From 87da87730f9f69fa29a73ac504b690c40b1bc98f Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 23 May 2023 15:32:20 +0200 Subject: [PATCH] Improve check for ANSI control escape sequences in Tramp * lisp/net/tramp-sh.el (tramp-barf-if-no-shell-prompt): Remove `ansi-color-control-seq-regexp'. * lisp/net/tramp.el (tramp-terminal-type): Fix docstring. (tramp-process-one-action): Delete ANSI control escape sequences in buffer. (Bug#63539) --- lisp/net/tramp-sh.el | 9 ++++----- lisp/net/tramp.el | 15 +++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index d4933ad7ba6..0b3ce07d275 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -4316,7 +4316,6 @@ seconds. If not, it produces an error message with the given ERROR-ARGS." proc timeout (rx (| (regexp shell-prompt-pattern) (regexp tramp-shell-prompt-pattern)) - (? (regexp ansi-color-control-seq-regexp)) eos)) (error (delete-process proc) @@ -5294,10 +5293,10 @@ function waits for output unless NOOUTPUT is set." (tramp-error proc 'file-error "Process `%s' not available, try again" proc)) (with-current-buffer (process-buffer proc) (let* (;; Initially, `tramp-end-of-output' is "#$ ". There might - ;; be leading escape sequences, which must be ignored. - ;; Busyboxes built with the EDITING_ASK_TERMINAL config - ;; option send also escape sequences, which must be - ;; ignored. + ;; be leading ANSI control escape sequences, which must be + ;; ignored. Busyboxes built with the EDITING_ASK_TERMINAL + ;; config option send also ANSI control escape sequences, + ;; which must be ignored. (regexp (rx (* (not (any "#$\n"))) (literal tramp-end-of-output) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index f986d65d944..b27465a98fa 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -697,7 +697,7 @@ See also `tramp-yesno-prompt-regexp'." (defcustom tramp-terminal-type "dumb" "Value of TERM environment variable for logging in to remote host. Because Tramp wants to parse the output of the remote shell, it is easily -confused by ANSI color escape sequences and suchlike. Often, shell init +confused by ANSI control escape sequences and suchlike. Often, shell init files conditionalize this setup based on the TERM environment variable." :group 'tramp :type 'string) @@ -5709,18 +5709,17 @@ Wait, until the connection buffer changes." "Wait for output from the shell and perform one action. See `tramp-process-actions' for the format of ACTIONS." (let ((case-fold-search t) - (shell-prompt-pattern - (rx (regexp shell-prompt-pattern) - (? (regexp ansi-color-control-seq-regexp)))) - (tramp-shell-prompt-pattern - (rx (regexp tramp-shell-prompt-pattern) - (? (regexp ansi-color-control-seq-regexp)))) tramp-process-action-regexp found todo item pattern action) (while (not found) ;; Reread output once all actions have been performed. ;; Obviously, the output was not complete. (while (tramp-accept-process-output proc)) + ;; Remove ANSI control escape sequences. + (with-current-buffer (tramp-get-connection-buffer vec) + (goto-char (point-min)) + (while (re-search-forward ansi-color-control-seq-regexp nil t) + (replace-match ""))) (setq todo actions) (while todo (setq item (pop todo) @@ -6280,7 +6279,7 @@ to cache the result. Return the modified ATTR." (with-tramp-file-property ,vec ,localname "file-attributes" (when-let ((attr ,attr)) (save-match-data - ;; Remove color escape sequences from symlink. + ;; Remove ANSI control escape sequences from symlink. (when (stringp (car attr)) (while (string-match ansi-color-control-seq-regexp (car attr)) (setcar attr (replace-match "" nil nil (car attr))))) -- 2.39.2