Skip to content

Commit

Permalink
fix: tab info now uses active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed May 3, 2024
1 parent 82f6880 commit fbed323
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
8 changes: 2 additions & 6 deletions internal/tui/run/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,8 @@ func (m model) View() string {
return m.tabs.View()
}

func (m model) TabSetInfo() string {
hasTabs, activeTab := m.tabs.Active()
if !hasTabs {
return ""
}
switch activeTab.Title {
func (m model) TabSetInfo(activeTabTitle string) string {
switch activeTabTitle {
case "plan":
return m.helpers.RunReport(m.run.PlanReport)
case "apply":
Expand Down
25 changes: 14 additions & 11 deletions internal/tui/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ type tabStatus interface {
}

// models implementing this can report info that'll be rendered on the opposite
// side away from the tab headers.
// side from from the tab headers.
type tabSetInfo interface {
TabSetInfo() string
// TabSetInfo is called with the name of the currently-active tab, or an
// empty string if there are no tabs. It is expected to return a widget to
// render.
TabSetInfo(active string) string
}

// TabSet is a related set of zero or more tabs, one of which is active, i.e.
Expand All @@ -40,6 +43,14 @@ type TabSet struct {
info tabSetInfo
}

// A tab is one of a set of tabs. A tab has a title, and an embedded model,
// which is responsible for the visible content under the tab.
type Tab struct {
tea.Model

Title string
}

func NewTabSet(width, height int) TabSet {
return TabSet{
width: width,
Expand Down Expand Up @@ -231,7 +242,7 @@ func (m TabSet) View() string {
rightSideInfo = Padded.Copy().
Width(remainingWidth).
Align(lipgloss.Right).
Render(m.info.TabSetInfo())
Render(m.info.TabSetInfo(m.ActiveTitle()))
}
tabHeadersFiller := lipgloss.JoinVertical(lipgloss.Top,
rightSideInfo,
Expand All @@ -258,11 +269,3 @@ func (m TabSet) contentWidth() int {
func (m TabSet) contentHeight() int {
return m.height - tabHeaderHeight
}

// A tab is one of a set of tabs. A tab has a title, and an embedded model,
// which is responsible for the visible content under the tab.
type Tab struct {
tea.Model

Title string
}

0 comments on commit fbed323

Please sign in to comment.