global-functions: introduce $FormatLine

This commit is contained in:
Christian Hesse 2023-04-20 23:15:04 +02:00
parent fb9feea595
commit cb338c76a8

View file

@ -29,6 +29,7 @@
:global DownloadPackage;
:global EitherOr;
:global EscapeForRegEx;
:global FormatLine;
:global GetMacVendor;
:global GetRandom20CharAlNum;
:global GetRandom20CharHex;
@ -329,6 +330,32 @@
:return $Return;
}
# format a line for output
:set FormatLine do={
:local Key [ :tostr $1 ];
:local Values [ :toarray $2 ];
:local Indent [ :tonum $3 ];
:local Spaces " ";
:local Return "";
:global EitherOr;
:global FormatLine;
:set Indent [ $EitherOr $Indent 16 ];
:if ([ :len $Key ] > 0) do={ :set Return ($Key . ":"); }
:if ([ :len $Key ] > ($Indent - 2)) do={
:set Return ($Return . "\n" . [ :pick $Spaces 0 $Indent ] . ($Values->0));
} else={
:set Return ($Return . [ :pick $Spaces 0 ($Indent - [ :len $Return ]) ] . ($Values->0));
}
:foreach Value in=[ :pick $Values 1 [ :len $Values ] ] do={
:set Return ($Return . "\n" . [ $FormatLine "" ({$Value}) $Indent ]);
}
:return $Return;
}
# get MAC vendor
:set GetMacVendor do={
:local Mac [ :tostr $1 ];