aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-04-20 23:15:04 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-04-24 22:26:26 +0200
commitcb338c76a8eb19a3ed1a73df330c3ddf638c7c39 (patch)
tree0dc45a1f68b4813ad142612763feac2716bf1912 /global-functions.rsc
parentfb9feea5950caec1c9bd7b9a3188cc312bf61956 (diff)
global-functions: introduce $FormatLine
Diffstat (limited to 'global-functions.rsc')
-rw-r--r--global-functions.rsc27
1 files changed, 27 insertions, 0 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index e682edc..501ea92 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -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 ];