From 1787b339c952bd27c376c655ccda39107c5ad320 Mon Sep 17 00:00:00 2001 From: Yuanlin Lin Date: Mon, 16 Oct 2023 23:56:24 +0800 Subject: [PATCH] feat(utils): Print multiline command in plan table --- pkg/zeaburpack/utils.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/zeaburpack/utils.go b/pkg/zeaburpack/utils.go index cdbf7a59..16ee6850 100644 --- a/pkg/zeaburpack/utils.go +++ b/pkg/zeaburpack/utils.go @@ -20,12 +20,12 @@ const ( // PrintPlanAndMeta prints the build plan and meta in a table format. func PrintPlanAndMeta(plan types.PlanType, meta types.PlanMeta, printFunc func(log string)) { table := fmt.Sprintf( - "\n%s╔══════════════════════════ %s%s %s═════════════════════════╗\n", + "\n%s╔══════════════════════════════ %s%s %s═════════════════════════════╗\n", blue, yellow, "Build Plan", blue, ) table += fmt.Sprintf( - "%s║%s %-16s %s│%s %-42s %s║%s\n", + "%s║%s %-16s %s│%s %-50s %s║%s\n", blue, reset, "provider", blue, reset, string(plan), blue, reset, ) @@ -33,15 +33,32 @@ func PrintPlanAndMeta(plan types.PlanType, meta types.PlanMeta, printFunc func(l if v == "" || v == "false" { continue } - table += blue + "║───────────────────────────────────────────────────────────────║\n" + reset - table += fmt.Sprintf( - "%s║%s %-16s %s│%s %-42s %s║\n%s", - blue, reset, k, blue, reset, v, blue, reset, - ) + table += blue + "║───────────────────────────────────────────────────────────────────────║\n" + reset + if strings.Contains(v, "\n") { + lines := strings.Split(v, "\n") + for i, line := range lines { + if i == 0 { + table += fmt.Sprintf( + "%s║%s %-16s %s│%s %-50s %s║\n", + blue, reset, k, blue, reset, line, blue, + ) + continue + } + table += fmt.Sprintf( + "%s║%s %-16s %s│%s %-50s %s║\n", + blue, reset, "", blue, reset, line, blue, + ) + } + } else { + table += fmt.Sprintf( + "%s║%s %-16s %s│%s %-50s %s║\n%s", + blue, reset, k, blue, reset, v, blue, reset, + ) + } } table += fmt.Sprintf( - "%s╚═══════════════════════════════════════════════════════════════╝%s\n", + "%s╚═══════════════════════════════════════════════════════════════════════╝%s\n", blue, reset, )