Skip to content

Commit

Permalink
add some color helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Sep 2, 2023
1 parent 4ada32a commit 87a824e
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions lib/console.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@

indentLine = l: " " + l;

colors = {
green = "32";
yellow = "33";
blue = "34";
magenta = "35";
colorOffsets = {
black = 0;
red = 1;
green = 2;
yellow = 3;
blue = 4;
magenta = 5;
cyan = 6;
white = 7;
};

colorsBased = base: builtins.mapAttrs (_: o: base + o) colorOffsets;

colors = colorsBased 30;

colorsBg = colorsBased 40;

colorsBright = colorsBased 90;

colorsBgBright = colorsBased 100;

color = n: t: "\\e[" + toString n + "m" + t + "\\e[0m";

in {
inherit indentLine color colors;
inherit indentLine color colors colorsBg colorsBright colorsBgBright;

indent = map indentLine;

bold = color "1";

s.colors = builtins.mapAttrs (_: color) colors;
s.colorsBg = builtins.mapAttrs (_: color) colorsBg;

rgb = r: g: b: color "48;2;${r};${g};${b}";

colorExt = n: color "48;5;${n}";
}

0 comments on commit 87a824e

Please sign in to comment.