journal/tool/lib/ansiLib.jq
2024-11-10 13:00:43 +00:00

24 lines
513 B
Plaintext

def supportsColour:
$ENV["JQ_SUPPORTS_COLOR"] == "1" or $ENV["JQ_SUPPORTS_COLOUR"] == "1" ;
def CSR:
"\u001b[";
def resetColours:
CSR + "0m";
def colourText($colourCode):
. as $text |
if supportsColour | not then
$text
else
CSR + ($colourCode | tostring) + "m" + $text + resetColours
end;
def colourText($colourCode; $mode):
. as $text |
if supportsColour | not then
$text
else
CSR + ($mode | tostring) + ";" + ($colourCode | tostring) + "m" + $text + resetColours
end;