Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Emacs library to convert strings into ansi
Emacs Lisp Makefile
Branch: master


latest commit a042c59544
@rejeep authored
Failed to load latest commit information.
test Update using new undercover API
.ert-runner Add .ert-runner file.
.gitignore Ignore ansi.elc
.travis.yml Add Emacs 24.4 to Travis config
Cask Add undercover test coverage


ansi.el Build Status Coverage Status

This package defines functions that turns simple strings to ansi strings. Turning a string into an ansi string can be to add color to a text, add color in the background of a text or adding a style, such as bold, underscore or italic.


Add ansi to your Cask file:

(depends-on "ansi")


All colors, background colors and styles can be accessed via a function with the ansi- prefix. For example:

;; Color text
(ansi-red "foo")
(ansi-blue "bar")

;; Color background
(ansi-on-red "foo")
(ansi-on-blue "bar")

;; Add style
(ansi-bold "foo")
(ansi-blink "bar")

It can become quite cumbersome to use those function names if the coloring is a little bit more advanced. To simplify this, there's a DSL, which makes this much more pleasant. If within a with-ansi block, the ansi- prefix is not necessary anymore. This is the same as the above.

;; Color text
 (red "foo")
 (blue "bar"))

;; Color background
 (on-red "foo")
 (on-blue "bar"))

;; Add style
 (bold "foo")
 (blink "bar"))

You can also use ansi-apply if you only have the name of the color:

(ansi-apply 'red "foo %s" "bar")


Ansi supports CSI codes, for example moving the cursor:

(ansi-down 3)
(ansi-csi-apply 'forward)
(ansi-csi-apply "J" 10)


Lets say you want to make a text bold, red and blinking. You can do this with nesting.

;; Without DSL
 (ansi-red (ansi-blink "foo bar")))

;; Using DSL
 (bold (red (blink "foo bar"))))
Something went wrong with that request. Please try again.