Skip to content
vic

Kabie/dye

Dyeing your terminal!

Kabie/dye.json
{
"createdAt": "2014-12-06T20:37:43Z",
"defaultBranch": "master",
"description": "Dyeing your terminal!",
"fullName": "Kabie/dye",
"homepage": null,
"language": "Elixir",
"name": "dye",
"pushedAt": "2024-03-02T18:31:26Z",
"stargazersCount": 21,
"topics": [
"elixir"
],
"updatedAt": "2024-03-02T18:23:05Z",
"url": "https://github.com/Kabie/dye"
}

Note: This lib uses uppercase sigil modifiers. So only works with elixir >= 1.1.0.

use Dye will replaces sigils: ~s and ~S.

iex(1)> use Dye
Dye
iex(2)> ~s"Red text"r
"\e[31mRed text\e[0m"
iex(3)> ~s"Bright red text"R
"\e[91mBright red text\e[0m"
iex(4)> ~s"Bright red text with green background"Rg
"\e[42;91mBright red text with green background\e[0m"
iex(5)> ~s"Underline"u
"\e[4mUnderline\e[0m"
iex(6)> ~s"Underline red text"ur
"\e[31;4mUnderline red text\e[0m"
iex(7)> ~s"Underline red text with bright green background"urG
"\e[102;31;4mUnderline red text with bright green background\e[0m"

$ mix test

Color modifiers demo

The first color modifier will be used as text color. If you only want to set background, you can set text then use I to inverse the color.

d: Default
k: Black
r: Red
g: Green
y: Yellow
b: Blue
m: Magenta
c: Cyan
w: White
K: Bright Black
R: Bright Red
G: Bright Green
Y: Bright Yellow
B: Bright Blue
M: Bright Magenta
C: Bright Cyan
W: Bright White
e: Don't reset at the end
I: Inverse text and background color
D: Bold
i: Italic
u: Underline
l: Blink slow
L: Blink rapid

The default implementation uses macro, which limits the modifiers can only be char list literal. The following won’t work:

mods = 'Rg'
sigil_S(<<"foo">>, mods)

To use the function implementation, simply do:

use Dye, func: true