Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Emacs library to convert strings into ansi

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 test
Octocat-spinner-32 vendor
Octocat-spinner-32 .ert-runner
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Cask
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.markdown
Octocat-spinner-32 ansi.el
README.markdown

ansi.el Build 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.