summaryrefslogtreecommitdiff
path: root/utilities/utilities.go
diff options
context:
space:
mode:
Diffstat (limited to 'utilities/utilities.go')
-rw-r--r--utilities/utilities.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go
index b976f77..a1ec805 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -220,3 +220,18 @@ type Pair[T1, T2 any] struct {
func PerSecondToInterval(rate int64) time.Duration {
return time.Duration(time.Second.Nanoseconds() / rate)
}
+
+func IndentOutput(output string, depth uint, character string) string {
+ finalNewline := false
+ if strings.LastIndex(output, "\n") == len(output)-1 {
+ finalNewline = true
+ output = strings.TrimSuffix(output, "\n")
+ }
+ indentedOutput := strings.Join(Fmap[string](strings.SplitAfter(output, "\n"), func(line string) string {
+ return strings.Repeat(character, int(depth)) + line
+ }), "")
+ if finalNewline {
+ indentedOutput += "\n"
+ }
+ return indentedOutput
+}