2018-08-06 18:19:39 +03:00
|
|
|
(defmodule Color
|
|
|
|
(hidden table)
|
|
|
|
(def table
|
2018-08-07 11:14:50 +03:00
|
|
|
{@"black" @"30"
|
|
|
|
@"red" @"31"
|
|
|
|
@"green" @"32"
|
|
|
|
@"yellow" @"33"
|
|
|
|
@"blue" @"34"
|
|
|
|
@"magenta" @"35"
|
|
|
|
@"cyan" @"36"
|
|
|
|
@"white" @"37"
|
|
|
|
@"reset" @"0"
|
|
|
|
@"none" @"0"
|
|
|
|
@"bold" @"1"
|
|
|
|
@"italic" @"3"
|
|
|
|
@"underline" @"4"
|
|
|
|
@"blink-slow" @"5"
|
|
|
|
@"blink-rapid" @"6"
|
|
|
|
@"bg-black" @"40"
|
|
|
|
@"bg-red" @"41"
|
|
|
|
@"bg-green" @"42"
|
|
|
|
@"bg-yellow" @"43"
|
|
|
|
@"bg-blue" @"44"
|
|
|
|
@"bg-magenta" @"45"
|
|
|
|
@"bg-cyan" @"46"
|
|
|
|
@"bg-white" @"47"})
|
2018-08-06 18:19:39 +03:00
|
|
|
|
|
|
|
(doc color "Generates ANSI coloration.")
|
|
|
|
(defn color [cname]
|
2018-08-07 11:14:50 +03:00
|
|
|
(let [n (Map.get &table cname)]
|
|
|
|
(String.append "\x1b[" &(String.append &n "m"))))
|
2018-08-06 18:19:39 +03:00
|
|
|
|
|
|
|
(doc colorize "Wraps a string in ANSI coloration and prints it.")
|
|
|
|
(defn colorize [cname s]
|
|
|
|
(String.append &(color cname) &(String.append s &(color "reset"))))
|
|
|
|
)
|
|
|
|
|
|
|
|
(defmodule IO
|
|
|
|
(doc color "Sets the output color using ANSI.")
|
|
|
|
(defn color [cname]
|
|
|
|
(print &(Color.color cname)))
|
|
|
|
|
|
|
|
(doc colorize "Wraps a string in ANSI coloration and prints it.")
|
|
|
|
(defn colorize [cname s]
|
|
|
|
(print &(Color.colorize cname s)))
|
|
|
|
)
|