Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Springclean: remove fruitsalad and other clutter from terraform plan command #302

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/tea_initialisesources.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ func (m initialiseSourcesModel) View() string {
if len(m.errors) > 0 {
view += fmt.Sprintf("\n%v\n", strings.Join(m.errors, "\n"))
}
if m.awsConfigForm != nil {
if m.awsConfigForm != nil && !m.awsConfigFormDone {
view += fmt.Sprintf("\n%v", m.awsConfigForm.View())
}
if m.profileInputForm != nil {
if m.profileInputForm != nil && !m.profileInputFormDone {
view += fmt.Sprintf("\n%v", m.profileInputForm.View())
}
if m.awsSourceRunning {
Expand Down
30 changes: 17 additions & 13 deletions cmd/tea_taskmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -68,7 +69,10 @@ func NewTaskModel(title string) taskModel {
status: taskStatusPending,
title: title,
spinner: spinner.New(
spinner.WithSpinner(spinner.Moon),
spinner.WithSpinner(spinner.Spinner{
Frames: []string{"∙∙∙∙∙∙∙", "●∙∙∙∙∙∙", "∙●∙∙∙∙∙", "∙∙●∙∙∙∙", "∙∙∙●∙∙∙", "∙∙∙∙●∙∙", "∙∙∙∙∙●∙", "∙∙∙∙∙∙●"},
FPS: time.Second / 7, //nolint:gomnd
}),
spinner.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(ColorPalette.Light.BgMain))),
),
}
Expand Down Expand Up @@ -103,25 +107,25 @@ func (m taskModel) Update(msg tea.Msg) (taskModel, tea.Cmd) {
}

func (m taskModel) View() string {
label := ""
switch m.status {
case taskStatusPending:
return fmt.Sprintf("⏳ %v", m.title)
label = m.spinner.Style.Render("pending:")
case taskStatusRunning:
v := m.spinner.View()
switch ansi.PrintableRuneWidth(v) {
case 0:
v = " "
case 1:
v += " "
label = m.spinner.View()
// all other lables are 7 cells wide
for ansi.PrintableRuneWidth(label) <= 7 {
label += " "
}
return fmt.Sprintf("%v %v", m.spinner.View(), m.title)
case taskStatusDone:
return fmt.Sprintf("✅ %v", m.title)
label = m.spinner.Style.Render("done: ")
case taskStatusError:
return fmt.Sprintf("⛔️ %v", m.title)
label = m.spinner.Style.Render("errored:")
case taskStatusSkipped:
return fmt.Sprintf("-- %v", m.title)
label = m.spinner.Style.Render("skipped:")
default:
return fmt.Sprintf("❓ %v", m.title)
label = m.spinner.Style.Render("unknown:")
}

return fmt.Sprintf("%v %v", label, m.title)
}
22 changes: 14 additions & 8 deletions cmd/tea_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,31 @@ func (m cmdModel) tokenChecks(token *oauth2.Token) (cmdModel, tea.Cmd) {
}

func (m cmdModel) View() string {
// show tasks in key order, skipping pending tasks to keep the ui uncluttered
allDone := true
tasks := make([]string, 0, len(m.tasks))
keys := make([]string, 0, len(m.tasks))
for k := range m.tasks {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
// when we're quitting due to a fatal error, don't show pending tasks as
// they are not relevant anymore
if m.fatalErrorSeen {
t, ok := m.tasks[k].(WithTaskModel)
if ok {
if t.TaskModel().status == taskStatusPending {
continue
}
t, ok := m.tasks[k].(WithTaskModel)
if ok {
if t.TaskModel().status != taskStatusDone {
allDone = false
}
if t.TaskModel().status == taskStatusPending {
continue
}

}
tasks = append(tasks, m.tasks[k].View())
}
if allDone {
// no need to show setup tasks after they're all done
tasks = []string{}
}
tasks = append(tasks, m.cmd.View())
if m.fatalError != "" {
tasks = append(tasks, markdownToString(fmt.Sprintf("> Fatal Error: %v\n", m.fatalError)))
Expand Down
10 changes: 7 additions & 3 deletions cmd/terraform_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,19 @@ func (m tfPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m tfPlanModel) View() string {
bits := []string{
m.planTask.View(),
bits := []string{}

if m.planTask.status != taskStatusPending {
bits = append(bits, m.planTask.View())
}

if m.runTfPlan && !m.tfPlanFinished {
bits = append(bits, markdownToString(m.planHeader))
}

bits = append(bits, m.processingTask.View())
if m.processingTask.status != taskStatusPending {
bits = append(bits, m.processingTask.View())
}

if m.tfPlanFinished {
bits = append(bits, m.processingHeader)
Expand Down
Loading