M-x eshell, and
M-x term in Emacs lets me save the buffer to a text file. But the terminal colors are not saved. How do I save the raw ANSI escape sequences too?
You can try something like the 100% guaranteed untested code below:
;;; -*- lexical-binding:t -*- (defun sm-save-proc-output () (interactive) (let ((buf (get-buffer-create "*SM-Saved-Proc-Output*")) (proc (get-buffer-process (current-buffer)))) (add-function :before (process-filter proc) (lambda (_proc string) (with-current-buffer buf (save-excursion (goto-char (point-max)) (insert string)))))))
It won't let you save the current content, but instead, sets up the buffer
*SM-Saved-Proc-Output* to receive a copy of all the output of the process running in the current buffer. You can then later save that buffer's content with
M-x write-region or