From 84eda5d3ab1aef7a3a789e65619f169af33fb9a4 Mon Sep 17 00:00:00 2001 From: unclegedd Date: Thu, 14 Mar 2024 20:12:56 -0500 Subject: [PATCH] WIP: hit l for logs --- src/pkg/bundle/tui/tui.go | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/pkg/bundle/tui/tui.go b/src/pkg/bundle/tui/tui.go index c54f5816..903b327d 100644 --- a/src/pkg/bundle/tui/tui.go +++ b/src/pkg/bundle/tui/tui.go @@ -3,7 +3,6 @@ package tui import ( "fmt" "os" - "regexp" "strconv" "strings" "time" @@ -86,6 +85,7 @@ func InitModel(client bndlClientShim, bundleYAML string) Model { logViewport := viewport.New(1000, 5) logViewport.MouseWheelEnabled = true + logViewport.MouseWheelDelta = 1 return Model{ bndlClient: client, @@ -149,11 +149,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if numComplete == m.totalPkgs { // check if last pkg is complete; if so, print success messages and quit m.done = true // remove the current view - line := strings.Repeat("─", WIDTH) + "\n" + line := lipgloss.NewStyle().Padding(0, 3).Render(strings.Repeat("─", WIDTH) + "\n") successCmds := []tea.Cmd{tea.Println(line)} for i := 0; i < m.totalPkgs; i++ { successStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#32A852")) - successMsg := fmt.Sprintf("✅ Package %s deployed", m.packages[i].name) + successMsg := fmt.Sprintf("\t✅ Package %s deployed", m.packages[i].name) successCmds = append(successCmds, tea.Println(successStyle.Render(successMsg))) } @@ -286,7 +286,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m Model) View() string { - line := strings.Repeat("─", WIDTH) + line := lipgloss.NewStyle().Padding(0, 3).Render(strings.Repeat("─", WIDTH)) if m.done { // clear the controlled Program's output return "" @@ -315,7 +315,7 @@ func (m Model) logView() string { lipgloss.WithWhitespaceForeground(subtle), ) ui := lipgloss.JoinHorizontal(lipgloss.Top, m.deployView()) - return fmt.Sprintf("%s\n%s\n", ui, box) + return fmt.Sprintf("%s\n%s\n", ui, lipgloss.NewStyle().Padding(0, 3).Render(box)) } func (m Model) deployView() string { @@ -333,30 +333,28 @@ func (m Model) deployView() string { text := lipgloss.NewStyle(). Align(lipgloss.Left). - Padding(0, 0). + Padding(0, 3). Render(fmt.Sprintf("%s Package %s deploying (%d / %d components)", p.spinner.View(), p.name, min(numComponentsSuccess+1, p.numComponents), p.numComponents)) if p.complete { text = lipgloss.NewStyle(). Align(lipgloss.Left). - Padding(0, 0). + Padding(0, 3). Render(fmt.Sprintf("✅ Package %s deployed", p.name)) } - view = lipgloss.JoinVertical(lipgloss.Left, view, text) + view = lipgloss.JoinVertical(lipgloss.Left, view, text+"\n") } return view } func (m Model) preDeployView() string { - header := "🎁 BUNDLE DEFINITION" - - prompt := "❓ Deploy this bundle? (y/n)" - - prettyYAML := colorPrintYAML(m.bundleYAML) - - line := strings.Repeat("─", WIDTH) + paddingStyle := lipgloss.NewStyle().Padding(0, 3) + header := paddingStyle.Render("🎁 BUNDLE DEFINITION") + prompt := paddingStyle.Render("❓ Deploy this bundle? (y/n)") + prettyYAML := paddingStyle.Render(colorPrintYAML(m.bundleYAML)) + line := paddingStyle.Render(strings.Repeat("─", WIDTH)) // Concatenate header, highlighted YAML, and prompt return fmt.Sprintf("\n%s\n\n%s\n\n%s\n\n%s", header, line, prettyYAML, prompt) @@ -411,12 +409,6 @@ func colorPrintYAML(yaml string) string { } outputYAML := p.PrintTokens(tokens) - - if zarfConfig.NoColor { - // If no color is specified strip any color codes from the output - https://regex101.com/r/YFyIwC/2 - ansiRegex := regexp.MustCompile(`\x1b\[(.*?)m`) - outputYAML = ansiRegex.ReplaceAllString(outputYAML, "") - } return outputYAML }