Skip to content
/ clansi Public
forked from ams-clj/clansi

ANSI color and style codes for Clojure.

License

Notifications You must be signed in to change notification settings

lgouger/clansi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLANSI

Installation

Add this to your leiningen `project.clj` depedencies

[com.bunimo/clansi "1.3.1-LPG-SNAPSHOT"]

…or to your deps.edn…

:deps {
    com.bunimo/clansi {:mvn/version "1.3.1-LPG-SNAPSHOT"}
}

Usage

ANSI colorization helper functions for Clojure programs.

You can call (clansi/style-test-page) to see what colors and styles are supported by your terminal.

Wrap strings in ANSI color and style codes like this:

(style "foo bar" :red)

(style "foo bar" :underline)

(style "foo bar" :blue :bg-red :underline)

You can turn the production of ANSI codes on or off by rebinding the clansi.core/*use-ansi* variable at runtime. This allows you to maintain only one version of your code with the strings marked up for color, and then turn ANSI on or off as desired, according to the properties of each output device, user preference, execution context, etc.

(without-ansi) and (with-ansi) convenience macros are provided for this purpose:

(defn print-colorized [] 
  (println (style "foo bar" :red)))

(print-colorized) ;; prints "foo bar" in red
(without-ansi (print-colorized)) ;; prints plain "foo bar", without any ANSI color codes
(without-ansi (with-ansi (print-colorized)) (print-colorized)) ;; prints a red "foo bar", then a plaintext "foo bar"

Deployment to Clojars

Update pom.xml

Link to original blog post

If no pom.xml exists use the following command to create it.

clojure -Spom

Once a pom.xml does exist, update the version in the file

Install the pack alias

Link to original blog post

Run the following command to add the :pack alias to you deps.edn file.

clojure -Sdeps '{:deps {pack/pack.alpha {:git/url "https://github.com/juxt/pack.alpha.git" :sha "dccf2134bcf03726a9465d2b9997c42e5cd91bff"}}}' -m mach.pack.alpha.inject 'c70740ffc10805f34836da2160fa1899601fac02'

Build your JAR

Link to original blog post

Use pack’s skinny jar mode to create a jar that’s suitable for upload to clojars.