/
colorize.clj
41 lines (35 loc) · 1.04 KB
/
colorize.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns ^{:doc "Functions dealing with making various forms of
Midje output be ergonomically colorful."}
midje.emission.colorize
(:require [colorize.core :as color]
[clojure.string :as str]
[midje.config :as config]
[midje.util.ecosystem :as ecosystem]))
;; This indirection is required so that the tests of this
;; file can fake the prerequisite
(def config-choice config/choice)
(defn- config-choice-as-string []
(let [choice (config-choice :colorize)]
(if (keyword? choice)
(name choice)
(str choice))))
(defn- colorize-string []
(str/upper-case (or (ecosystem/getenv "MIDJE_COLORIZE")
(config-choice-as-string))))
(defn init! []
(case (colorize-string)
"TRUE"
(do
(def fail color/red)
(def pass color/green)
(def note color/cyan))
"REVERSE"
(do
(def fail color/red-bg)
(def pass color/green-bg)
(def note color/cyan-bg))
;; else
(do
(def fail str)
(def pass str)
(def note str))))