Name ANSI color codes

This commit is contained in:
Andrew Kvalheim 2023-11-28 09:20:10 -08:00
parent b03a542a42
commit 4e8caf4ebf
2 changed files with 52 additions and 40 deletions

View file

@ -3,6 +3,8 @@
let
inherit (lib) concatLines concatStringsSep genAttrs mapAttrsToList toShellVar;
palette = import ../resources/palette.nix { inherit lib; };
toAbbrs = kv: concatLines (mapAttrsToList (k: v: "abbr ${toShellVar k v}") kv);
in
{
@ -137,44 +139,44 @@ in
undo = "git restore --patch";
};
home.sessionVariables.EXA_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") {
ur = "2;37"; # the user-read permission bit
uw = "2;37"; # the user-write permission bit
ux = "1;32"; # the user-execute permission bit for regular files
ue = "1;32"; # the user-execute for other file kinds
gr = "2;37"; # the group-read permission bit
gw = "2;37"; # the group-write permission bit
gx = "2;37"; # the group-execute permission bit
tr = "1;35"; # the others-read permission bit
tw = "1;31"; # the others-write permission bit
tx = "2;37"; # the others-execute permission bit
su = "1;33"; # setuid, setgid, and sticky permission bits for files
sf = "1;33"; # setuid, setgid, and sticky for other file kinds
xa = "1;33"; # the extended attribute indicator
sn = "2;37"; # the numbers of a files size
ub = "1;37"; # the units of a files size if it is lower than 1 KB/Kib
uk = "1;34"; # the units of a files size if it is between 1 KB/KiB and 1 MB/MiB
um = "1;33"; # the units of a files size if it is between 1 MB/MiB and 1 GB/GiB
ug = "1;31"; # the units of a files size if it is between 1 GB/GiB and 1 TB/TiB
ut = "1;31"; # the units of a files size if it is 1 TB/TiB or higher
uu = "30"; # a user thats you
un = "31"; # a user thats someone else
gu = "30"; # a group that you belong to
gn = "31"; # a group you arent a member of
da = "2;3;37"; # a files date
lp = "2;37"; # the path of a symlink
cc = "1;33"; # an escaped character in a filename
});
home.sessionVariables.EXA_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") (with palette.ansi; {
ur = dim.white; # the user-read permission bit
uw = dim.white; # the user-write permission bit
ux = bold.green; # the user-execute permission bit for regular files
ue = bold.green; # the user-execute for other file kinds
gr = dim.white; # the group-read permission bit
gw = dim.white; # the group-write permission bit
gx = dim.white; # the group-execute permission bit
tr = bold.magenta; # the others-read permission bit
tw = bold.red; # the others-write permission bit
tx = dim.white; # the others-execute permission bit
su = bold.yellow; # setuid, setgid, and sticky permission bits for files
sf = bold.yellow; # setuid, setgid, and sticky for other file kinds
xa = bold.yellow; # the extended attribute indicator
sn = dim.white; # the numbers of a files size
ub = bold.white; # the units of a files size if it is lower than 1 KB/Kib
uk = bold.blue; # the units of a files size if it is between 1 KB/KiB and 1 MB/MiB
um = bold.yellow; # the units of a files size if it is between 1 MB/MiB and 1 GB/GiB
ug = bold.red; # the units of a files size if it is between 1 GB/GiB and 1 TB/TiB
ut = bold.red; # the units of a files size if it is 1 TB/TiB or higher
uu = black; # a user thats you
un = red; # a user thats someone else
gu = black; # a group that you belong to
gn = red; # a group you arent a member of
da = dim.italic.white; # a files date
lp = dim.white; # the path of a symlink
cc = bold.yellow; # an escaped character in a filename
}));
home.sessionVariables.LS_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") {
di = "1;36"; # directories
ex = "32"; # executable files
fi = "37"; # regular files
pi = "3;34"; # named pipes
so = "3;34"; # sockets
bd = "1;34"; # block devices
cd = "1;34"; # character devices
ln = "35"; # symlinks
or = "31"; # symlinks with no target
});
home.sessionVariables.LS_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") (with palette.ansi; {
di = bold.cyan; # directories
ex = green; # executable files
fi = white; # regular files
pi = italic.blue; # named pipes
so = italic.blue; # sockets
bd = bold.blue; # block devices
cd = bold.blue; # character devices
ln = magenta; # symlinks
or = red; # symlinks with no target
}));
}

View file

@ -1,9 +1,12 @@
{ lib }:
let
inherit (builtins) mapAttrs substring;
inherit (builtins) listToAttrs mapAttrs substring;
inherit (lib) imap0 nameValuePair;
inherit ((import <nix-colors> { }).lib.conversions) hexToRGB;
ansiNames = [ "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" ];
asHex = {
# Monokai
black = "#1b1b1b";
@ -36,6 +39,13 @@ let
};
in
asHex // rec {
ansi =
let
base = listToAttrs (imap0 (i: n: nameValuePair n (toString (30 + i))) ansiNames);
effect = p: mapAttrs (_: a: "${p};${a}") base;
in
base // { bold = effect "1"; dim = effect "2" // { italic = effect "2;3"; }; italic = effect "3"; };
asFloat = mapAttrs (_: cs: map (c: c / 255.0) cs) asInt;
asInt = mapAttrs (_: h: hexToRGB (substring 1 6 h)) asHex;