Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (66 sloc) 1.82 KB

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"))))