From fbed323d1d5a750743a574c6a6d81fd90d482c2b Mon Sep 17 00:00:00 2001 From: Louis Garman Date: Fri, 3 May 2024 07:54:04 +0100 Subject: [PATCH] fix: tab info now uses active tab --- internal/tui/run/model.go | 8 ++------ internal/tui/tabs.go | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/internal/tui/run/model.go b/internal/tui/run/model.go index d85476cc..ea1fa742 100644 --- a/internal/tui/run/model.go +++ b/internal/tui/run/model.go @@ -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": diff --git a/internal/tui/tabs.go b/internal/tui/tabs.go index e0cc7046..25907ba9 100644 --- a/internal/tui/tabs.go +++ b/internal/tui/tabs.go @@ -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. @@ -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, @@ -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, @@ -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 -}