Skip to content

Commit

Permalink
Implement hideStartupStatusMsg to hid the status messages after the f…
Browse files Browse the repository at this point in the history
…irst command ran

This allows targeted removal of the messages that persist in terminal
history before the initial terraform plan or apply runs
  • Loading branch information
DavidS-ovm committed May 23, 2024
1 parent 40d23a5 commit 6dbeab5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
50 changes: 26 additions & 24 deletions cmd/tea_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ type cmdModel struct {
frozen bool
frozenView string // this gets set if the view is frozen, and will be used to render the last view using the cliExecCommand

hideStartupStatus bool

// business logic. This model will implement the actual CLI functionality requested.
cmd tea.Model
}

type freezeViewMsg struct{}
type unfreezeViewMsg struct{}

type hideStartupStatusMsg struct{}

type delayQuitMsg struct{}

// fatalError is a wrapper for errors that should abort the running tea.Program.
Expand Down Expand Up @@ -108,6 +112,8 @@ func (m *cmdModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case unfreezeViewMsg:
m.frozen = false
m.frozenView = ""
case hideStartupStatusMsg:
m.hideStartupStatus = true

case fatalError:
log.WithError(msg.err).WithField("msg.id", msg.id).Debug("cmdModel: fatalError received")
Expand Down Expand Up @@ -202,35 +208,31 @@ func (m cmdModel) View() string {
if m.frozen {
return ""
}
// 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 {
t, ok := m.tasks[k].(WithTaskModel)
if ok {
if t.TaskModel().status != taskStatusDone {
allDone = false
}
if t.TaskModel().status == taskStatusPending {
continue
bits := []string{}

if !m.hideStartupStatus {
// show tasks in key order, skipping pending bits to keep the ui uncluttered
keys := make([]string, 0, len(m.tasks))
for k := range m.tasks {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
t, ok := m.tasks[k].(WithTaskModel)
if ok {
if t.TaskModel().status == taskStatusPending {
continue
}
}
bits = append(bits, m.tasks[k].View())
}
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())

bits = append(bits, m.cmd.View())
if m.fatalError != "" {
tasks = append(tasks, markdownToString(fmt.Sprintf("> Fatal Error: %v\n", m.fatalError)))
bits = append(bits, markdownToString(fmt.Sprintf("> Fatal Error: %v\n", m.fatalError)))
}
return strings.Join(tasks, "\n")
return strings.Join(bits, "\n")
}

var applyOnlyArgs = []string{
Expand Down
3 changes: 3 additions & 0 deletions cmd/terraform_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func (m tfApplyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
})
}
case submitPlanNowMsg:
cmds = append(cmds, func() tea.Msg { return hideStartupStatusMsg{} })

case submitPlanFinishedMsg:
cmds = append(cmds, func() tea.Msg { return startStartingSnapshotMsg{} })
Expand Down Expand Up @@ -266,6 +268,7 @@ func (m tfApplyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.isEnding = true
cmds = append(cmds,
func() tea.Msg { return unfreezeViewMsg{} },
func() tea.Msg { return hideStartupStatusMsg{} },
m.endingChangeSnapshot.Init(),
m.startEndChangeCmd(),
m.waitForEndingActivity,
Expand Down
3 changes: 3 additions & 0 deletions cmd/terraform_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (m tfPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, func() tea.Msg { return submitPlanNowMsg{} })
}

case submitPlanNowMsg:
cmds = append(cmds, func() tea.Msg { return hideStartupStatusMsg{} })

case submitPlanFinishedMsg:
cmds = append(cmds, func() tea.Msg { return delayQuitMsg{} })
}
Expand Down

0 comments on commit 6dbeab5

Please sign in to comment.