Skip to content

HTTPS clone URL

Subversion checkout URL

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

v0.4.1

latest commit a042c59544
@rejeep authored
Failed to load latest commit information.
test
.ert-runner Add .ert-runner file.
.gitignore
.travis.yml Add Emacs 24.4 to Travis config
Cask
Makefile Improve Makefile tasks
README.markdown Add Coveralls badge
ansi.el v0.4.1

README.markdown

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.

Installation

Add ansi to your Cask file:

(depends-on "ansi")

Usage

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
(with-ansi
 (red "foo")
 (blue "bar"))

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

;; Add style
(with-ansi
 (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")

CSI

Ansi supports CSI codes, for example moving the cursor:

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

Nesting

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

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

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