From cb338c76a8eb19a3ed1a73df330c3ddf638c7c39 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 20 Apr 2023 23:15:04 +0200 Subject: global-functions: introduce $FormatLine --- global-functions.rsc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 ]; -- cgit v1.2.3-70-g09d2