mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
- don’t do function copying in benchmarking - fix the array_update benchmark - add Filepath.file-from-path - add tests for the `Filepath` module - reformat a lot of documentation
49 lines
1.3 KiB
Plaintext
49 lines
1.3 KiB
Plaintext
(defmodule Color
|
|
(hidden table)
|
|
(def table
|
|
{@"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"})
|
|
|
|
(doc color "generates ANSI coloration based on a color name `cname`.")
|
|
(defn color [cname]
|
|
(let [n (Map.get &table cname)]
|
|
(String.append "\x1b[" &(String.append &n "m"))))
|
|
|
|
(doc colorize "wraps a string `s` in ANSI coloration based on a color name `cname` and prints it.
|
|
|
|
It will reset the color afterwards.")
|
|
(defn colorize [cname s]
|
|
(String.append &(color cname) &(String.append s &(color "reset"))))
|
|
)
|
|
|
|
(defmodule IO
|
|
(doc color "sets the output color using ANSI coloration based on a color name `cname`.")
|
|
(defn color [cname]
|
|
(print &(Color.color cname)))
|
|
|
|
(doc colorize "wraps a string in ANSI coloration based on a color name `cname` and prints it.")
|
|
(defn colorize [cname s]
|
|
(print &(Color.colorize cname s)))
|
|
)
|