This commit is contained in:
chaos 2024-11-10 16:49:02 +00:00
parent d2d8e85eff
commit b6b3b29111

View file

@ -46,22 +46,14 @@ def colourEscapes:
); );
def _encodeJSONValuePlainPretty($indent; $currentDepth): def _encodeJSONValuePlainPretty($indent; $currentDepth):
(if $indent > 0 then [range($indent * $currentDepth) | " "] | join("") else "" end) as $currentIndentDepthIndent | [range($indent * $currentDepth) | " "] | join("") as $currentIndentDepthIndent |
(if $indent > 0 then [range($indent * ($currentDepth + 1)) | " "] | join("") else "" end) as $nextDepthIndent | [range($indent * ($currentDepth + 1)) | " "] | join("") as $nextDepthIndent |
(if $indent > 0 then "\n" else "" end) as $currentIndentDepthNewline | "\n" as $currentIndentDepthNewline |
(if $indent > 0 then " " else "" end) as $currentIndentDepthSpace | " " as $currentIndentDepthSpace |
. as $value | . as $value |
(. | type) as $valueType | (. | type) as $valueType |
if $valueType == "null" then if $valueType == "array" then
"null"
elif $valueType == "boolean" then
if $value then "true" else "false" end
elif $valueType == "number" then
$value | tostring
elif $valueType == "string" then
$value | tojson
elif $valueType == "array" then
($value | length) as $numValues | ($value | length) as $numValues |
if $numValues > 0 then if $numValues > 0 then
@ -100,6 +92,8 @@ def _encodeJSONValuePlainPretty($indent; $currentDepth):
else else
"{}" "{}"
end end
else
tojson
end; end;
def _encodeJSONValueColourCompact: def _encodeJSONValueColourCompact:
@ -158,10 +152,10 @@ def _encodeJSONValueColourPretty($indent; $currentDepth):
def colourText($text; $kind): def colourText($text; $kind):
ansiLib::CSR + $escapes[$kind] + "m" + $text + ansiLib::CSR + "0m"; ansiLib::CSR + $escapes[$kind] + "m" + $text + ansiLib::CSR + "0m";
(if $indent > 0 then [range($indent * $currentDepth) | " "] | join("") else "" end) as $currentIndentDepthIndent | ([range($indent * $currentDepth) | " "] | join("")) as $currentIndentDepthIndent |
(if $indent > 0 then [range($indent * ($currentDepth + 1)) | " "] | join("") else "" end) as $nextDepthIndent | ([range($indent * ($currentDepth + 1)) | " "] | join("")) as $nextDepthIndent |
(if $indent > 0 then "\n" else "" end) as $currentIndentDepthNewline | "\n" as $currentIndentDepthNewline |
(if $indent > 0 then " " else "" end) as $currentIndentDepthSpace | " " as $currentIndentDepthSpace |
. as $value | . as $value |
(. | type) as $valueType | (. | type) as $valueType |