From bada399fdb63c4dcbbde51af9a38f963ba41cafa Mon Sep 17 00:00:00 2001 From: unclegedd Date: Fri, 15 Mar 2024 10:19:53 -0500 Subject: [PATCH] WIP: hit l for logs --- src/pkg/bundle/tui/tui.go | 42 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/pkg/bundle/tui/tui.go b/src/pkg/bundle/tui/tui.go index c54f5816..8948a83b 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,14 +286,14 @@ 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 "" } else if m.viewLogs { - return fmt.Sprintf("%s\n%s", line, m.logView()) + return fmt.Sprintf("%s\n%s%s", line, m.deployView(), m.logView()) } else if m.confirmed { - return fmt.Sprintf("%s\n%s", line, m.deployView()) + return fmt.Sprintf("%s\n%s\n\n\n", line, m.deployView()) } return "" } @@ -314,12 +314,13 @@ func (m Model) logView() string { boxStyle.Render(m.viewport.View()), lipgloss.WithWhitespaceForeground(subtle), ) - ui := lipgloss.JoinHorizontal(lipgloss.Top, m.deployView()) - return fmt.Sprintf("%s\n%s\n", ui, box) + //ui := lipgloss.JoinHorizontal(lipgloss.Top, m.deployView()) + return fmt.Sprintf("\n%s\n", lipgloss.NewStyle().Padding(0, 3).Render(box)) } func (m Model) deployView() string { view := "" + logMsg := lipgloss.NewStyle().Padding(0, 3).Render("\n📜 View logs (l/L)") for _, p := range m.packages { // count number of successful components numComponentsSuccess := 0 @@ -333,30 +334,29 @@ 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, logMsg, view, text+"\n") } return view } +// todo: don't tea.Print this, but do print it at the end? 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 +411,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 }