atomontage / xterm-color

ANSI & xterm-256 color text property translator for Emacs
BSD 2-Clause "Simplified" License
219 stars 20 forks source link

How to correctly apply the filter to `make-process` buffer #39

Closed ezchi closed 1 year ago

ezchi commented 3 years ago

Try to use filter on make-process as below:

(let ((process-environment (add-to-list 'process-environment "TERM=xterm-256color")))
    (make-process :command (list "sh" "-c" "scons")
                               :buffer "*foo*"
                               :filter (lambda (_process string) (xterm-color-filter string))))

But I still not get color in the process buffer:

^[[90m# seed = random
^[[32m# Info ....
atomontage commented 1 year ago

The filter function needs to execute in the context of the given buffer (since it keeps buffer-local state). You can use something like:

(with-current-buffer "*foo*" (insert (xterm-color-filter string)))