├── .gitignore ├── test.clj ├── README.textile └── cojor.clj /.gitignore: -------------------------------------------------------------------------------- 1 | *.sw? 2 | -------------------------------------------------------------------------------- /test.clj: -------------------------------------------------------------------------------- 1 | (use 'cojor) 2 | (test #'str-col) 3 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | Colourful strings in Clojure. 2 | 3 | h3. Colours 4 | 5 | * red 6 | * green 7 | * yellow 8 | * blue 9 | * purple 10 | * lightblue 11 | * white 12 | 13 | h3. Examples 14 | 15 | Functions named after a colour will return a string wrapped with colour escape codes. Functions postfixed with ln will print a line in that colour. 16 | 17 |
18 | (use 'cojor)
19 | (println (red "hello"))
20 | (println (green "hello"))
21 | (greenln "hello")
22 | (blueln "hello")
23 | 
24 | 25 | All colour named methods call this function: 26 | 27 |
28 | (str-col :red "hello")
29 | 
30 | -------------------------------------------------------------------------------- /cojor.clj: -------------------------------------------------------------------------------- 1 | (ns cojor) 2 | 3 | (def colors { 4 | :start "\033[", 5 | :end "\033[0m", 6 | :red "31", 7 | :green "32", 8 | :yellow "33", 9 | :blue "34", 10 | :purple "35", 11 | :lightblue "36", 12 | :white "37" 13 | }) 14 | 15 | (defn 16 | #^{:test (fn [] 17 | (assert (re-find #"\[0m" (str-col :red "test"))) 18 | (assert (re-find #"\[0m$" (str-col :red "test"))) 19 | )} 20 | str-col 21 | [col message] 22 | (str (colors :start) (colors col) "m" message (colors :end))) 23 | 24 | (defn pln-col [col message] 25 | (println (str-col col message))) 26 | 27 | (doseq [col (map name (keys colors))] 28 | (intern 'cojor (symbol col) (partial str-col (keyword col))) 29 | (intern 'cojor (symbol (str col "ln")) (partial pln-col (keyword col)))) 30 | --------------------------------------------------------------------------------