reddit / emacs

Help with process filters

Substantial_Quit_481 · 2022-08-20 05:49
I often start processes which print their progress on a terminal, but the output gets printed messily in the process buffer. For example Reading track 1 of 4 (1 of 9) ... 0 %^MReading track 1 of 4 (1 of 9) ... 1 %^MReading track 1 of 4 (1 of 9) ... 2 %^MReading track 1 of 4 (1 of 9) ... 3 % Where the `^M` is a newline character, I guess. How could I print progress like it does on a terminal into the process buffer, overwriting the previous % and respecting newlines? I have looked at process filters but cannot understand how I would write one.
xenodium · 2022-08-20 08:01
shell-mode in the process buffer may help: (with-current-buffer proc-buffer (require 'shell) (shell-mode)) and set filter to `comint-output-filter`. ps. You can see colors in buffer in some of the sample animations https://github.com/xenodium/dwim-shell-command#focus using the above.
eli-zaretskii · 2022-08-20 08:03
You need to process the ^M characters by erasing everything before it. (There are now newlines in the process output: it relies on the ^M to home the cursor on the terminal.)
7890yuiop · 2022-08-20 10:52
`^M` (ASCII 13) is a carriage return, rather than a newline. (A newline character is ASCII 10, `^J`.)
Substantial_Quit_481 · 2022-08-20 14:49
This works perfectly, thanks!