xterm-color.el is an ANSI control sequence to text-property translator
- Regular ANSI color support
- XTERM 256 color support
- Works with compilation-mode (experimental)
- Works with eshell
- Bonus: Faster than ansi-color.el
Call xterm-color-filter to propertize strings that you can then insert into a buffer. All state is kept in buffer-local variables which means that control sequences can span xterm-color-filter call boundaries.
(xterm-color-filter "�[0;1;3;4") (xterm-color-filter ";35") (xterm-color-filter ";mThis is only a test") (xterm-color-filter "�[0m")
You may also use xterm-color-colorize-buffer, interactively or from elisp, to colorize an entire buffer.
If you are inserting into a buffer that has activated font locking, you NO LONGER need to set font-lock-unfontify-region-function to xterm-color-unfontify-region as the latter has been removed.
You can replace ansi-color.el with xterm-color for all comint buffers:
;; comint install (progn (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter) (setq comint-output-filter-functions (remove 'ansi-color-process-output comint-output-filter-functions))) ;; comint uninstall (progn (remove-hook 'comint-preoutput-filter-functions 'xterm-color-filter) (add-to-list 'comint-output-filter-functions 'ansi-color-process-output)) ;; For M-x shell, also set TERM accordingly (xterm-256color) ;; You can also use it with eshell (and thus get color output from system ls): (require 'eshell) (add-hook 'eshell-mode-hook (lambda () (setq xterm-color-preserve-properties t))) (add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter) (setq eshell-output-filter-functions (remove 'eshell-handle-ansi-color eshell-output-filter-functions)) ;; Don't forget to setenv TERM xterm-256color
You may use `compilation-shell-minor-mode’ with comint-mode buffers (e.g. M-x shell) and the comint configuration previously described.
For standalone compilation buffers use the following configuration:
(setq compilation-environment '("TERM=xterm-256color")) (add-hook 'compilation-start-hook (lambda (proc) ;; We need to differentiate between compilation-mode buffers ;; and running as part of comint (which at this point we assume ;; has been configured separately for xterm-color) (when (eq (process-filter proc) 'compilation-filter) ;; This is a process associated with a compilation-mode buffer. ;; We may call `xterm-color-filter' before its own filter function. (set-process-filter proc (lambda (proc string) (funcall 'compilation-filter proc (xterm-color-filter string)))))))
Standalone compilation-mode buffer support is experimental, report any issues that may arise.
M-x xterm-color-test For comint or eshell: M-x shell || M-x eshell perl tests/xterm-colortest && perl tests/256colors2.pl
The code comes with a BSD-style license so you can basically do with it whatever you want.
xristos (AT) sdf (DOT) lonestar (DOT) org