ANSI & xterm-256 color text property translator for Emacs
Emacs Lisp Perl
Switch branches/tags
Latest commit 42374a9 Feb 3, 2018
atomontage Release 1.7
+ Better documentation and configuration examples

+ It is no longer recommended to insert xterm-color-filter
  in the global comint-preoutput-filter-functions but only
  insert it (as the first hook) in the buffer-local variable
  for comint-derived modes.

+ Exposed xterm-color-256

+ Added autoloads

+ CSI interpretation for sequences that move the cursor is
  now configurable via xterm-color-ignore-movement
Failed to load latest commit information.
img moved images to img/ Dec 28, 2016
tests added tests Jul 26, 2015 Release 1.7 Feb 2, 2018
xterm-color.el Release 1.7 Feb 2, 2018

xterm-color.el is an ANSI control sequence to text-property translator


  • Regular ANSI color support
  • XTERM 256 color support
  • Works with compilation-mode
  • 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, but this may create problems with modes that propertize strings and feed them through comint-preoutput-filter-functions since xterm-color-filter will strip all text properties.

The recommended configuration is to remove ansi-color-process-output from comint-output-filter-functions and add xterm-color-filter as the first hook in the buffer-local comint-preoutput-filter-functions for any comint-based mode that you would like it to affect (e.g. shell-mode).

An example configuration for shell-mode (M-x shell) is shown below:

(setq comint-output-filter-functions
      (remove 'ansi-color-process-output comint-output-filter-functions))

(add-hook 'shell-mode-hook
          (lambda () (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter nil t)))

;; 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-before-prompt-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 shell-mode buffers and the 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.
               (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/

img/xterm-thumb.png img/godwars2-thumb.png


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