Skip to content

Commit

Permalink
WIP: hit l for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed Mar 15, 2024
1 parent 66d6c68 commit bada399
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/pkg/bundle/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tui
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
}

Expand Down Expand Up @@ -286,14 +286,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m Model) View() string {

Check warning on line 288 in src/pkg/bundle/tui/tui.go

View workflow job for this annotation

GitHub Actions / validate

exported method Model.View should have comment or be unexported
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 ""
}
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit bada399

Please sign in to comment.