From 4454bc2ec1bd6a0e1774b9792515089fc2b9970d Mon Sep 17 00:00:00 2001 From: "pieter.noordhuis" Date: Tue, 17 Nov 2026 20:22:04 +0000 Subject: [PATCH] cmdio: split each View into render and keep the theme builder Every TUI model's View becomes a one-line wrapper around render(), so the next change can route key handling through the teainput decoder without touching the rendering. libs/apps/prompt gets a Theme alias for the huh theme and its builder is named appkitStyles, which cmd/apps uses through prompt.Theme instead of importing huh types directly. Behaviour is unchanged and no pin golden moves. select keeps its tea.HideCursor in Init: removing it drops one "?25 reset" from TestModesPin_Select, which is a golden change, so that removal waits for the v2 swap that drops tea.HideCursor. Co-authored-by: Isaac --- cmd/air/list_tui.go | 4 +++- cmd/apps/init.go | 4 ++-- libs/apps/prompt/prompt.go | 13 ++++++++----- libs/apps/prompt/prompt_test.go | 4 ++-- libs/cmdio/pager.go | 4 +++- libs/cmdio/prompt.go | 4 +++- libs/cmdio/select.go | 4 +++- libs/cmdio/spinner.go | 4 +++- libs/tableview/tableview.go | 4 +++- 9 files changed, 30 insertions(+), 15 deletions(-) diff --git a/cmd/air/list_tui.go b/cmd/air/list_tui.go index 9f5e37fb3b3..cdcb0cf1595 100644 --- a/cmd/air/list_tui.go +++ b/cmd/air/list_tui.go @@ -335,7 +335,9 @@ func (m listModel) clampedOffset() int { return max(offset, 0) } -func (m listModel) View() string { +func (m listModel) View() string { return m.render() } + +func (m listModel) render() string { if m.mode == modeDetail { faint := m.styles.r.NewStyle().Foreground(colN7) lines := []string{m.detailTitle} diff --git a/cmd/apps/init.go b/cmd/apps/init.go index ed79271d25f..ad69d79bd19 100644 --- a/cmd/apps/init.go +++ b/cmd/apps/init.go @@ -679,7 +679,7 @@ func promptForPluginsAndDeps(ctx context.Context, m *manifest.Manifest, preSelec // asks per resource that can be accessed on behalf of the user. // Resources that cannot are listed as info and resolve to sp. // Returns a map of resource key to auth mode, or nil if nothing needs to be asked. -func promptForAuthModes(ctx context.Context, resources []manifest.Resource, theme *huh.Theme) (map[string]string, error) { +func promptForAuthModes(ctx context.Context, resources []manifest.Resource, theme prompt.Theme) (map[string]string, error) { var capable []manifest.Resource for _, r := range resources { if r.Scope != "" && !r.AppOnly { @@ -751,7 +751,7 @@ func authModeLabel(mode string) string { // promptForResource prompts the user for a resource value. // Returns a map of value keys to values. For single-field resources the key is "resource_key.field". // For multi-field resources, keys use "resource_key.field_name". -func promptForResource(ctx context.Context, r manifest.Resource, theme *huh.Theme, required bool) (map[string]string, error) { +func promptForResource(ctx context.Context, r manifest.Resource, theme prompt.Theme, required bool) (map[string]string, error) { if fn, ok := prompt.GetPromptFunc(r.Type); ok { if !required { var configure bool diff --git a/libs/apps/prompt/prompt.go b/libs/apps/prompt/prompt.go index 9cef046c8f7..411bba7747c 100644 --- a/libs/apps/prompt/prompt.go +++ b/libs/apps/prompt/prompt.go @@ -37,14 +37,17 @@ var ( colorDimmedDark cmdio.Color = lipgloss.Color("#52525B") ) +// Theme is the huh theme handed to appkit prompt forms and fields. +type Theme = *huh.Theme + // AppkitTheme returns a custom theme for appkit prompts. -func AppkitTheme() *huh.Theme { - return appkitTheme(cmdio.HasDarkBackground()) +func AppkitTheme() Theme { + return appkitStyles(cmdio.HasDarkBackground()) } -// appkitTheme builds the theme for a known background, matching the shape of -// huh v2's ThemeFunc. -func appkitTheme(isDark bool) *huh.Theme { +// appkitStyles builds the appkit styles on top of huh's base theme for a known +// background, matching the shape of huh v2's ThemeFunc. +func appkitStyles(isDark bool) *huh.Theme { lightDark := cmdio.LightDark(isDark) t := huh.ThemeBase() diff --git a/libs/apps/prompt/prompt_test.go b/libs/apps/prompt/prompt_test.go index b9116cd621d..76d64c8b6d7 100644 --- a/libs/apps/prompt/prompt_test.go +++ b/libs/apps/prompt/prompt_test.go @@ -557,6 +557,6 @@ func TestListSystemAIModelServicesWithoutAccess(t *testing.T) { } func TestAppkitThemeDimmedButtonFollowsBackground(t *testing.T) { - assert.Equal(t, colorDimmedDark, appkitTheme(true).Focused.BlurredButton.GetForeground()) - assert.Equal(t, colorDimmedLight, appkitTheme(false).Focused.BlurredButton.GetForeground()) + assert.Equal(t, colorDimmedDark, appkitStyles(true).Focused.BlurredButton.GetForeground()) + assert.Equal(t, colorDimmedLight, appkitStyles(false).Focused.BlurredButton.GetForeground()) } diff --git a/libs/cmdio/pager.go b/libs/cmdio/pager.go index 0ecb330e5cd..7aff1608486 100644 --- a/libs/cmdio/pager.go +++ b/libs/cmdio/pager.go @@ -230,7 +230,9 @@ func (m *pagerModel[T]) startDrain() tea.Cmd { return m.fetch(m.pageSize, m.limit, m.total) } -func (m *pagerModel[T]) View() string { +func (m *pagerModel[T]) View() string { return m.render() } + +func (m *pagerModel[T]) render() string { switch { case m.iterDone || m.err != nil: return "" diff --git a/libs/cmdio/prompt.go b/libs/cmdio/prompt.go index 513fc76b997..ce0fc674872 100644 --- a/libs/cmdio/prompt.go +++ b/libs/cmdio/prompt.go @@ -204,7 +204,9 @@ func (m *promptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } -func (m *promptModel) View() string { +func (m *promptModel) View() string { return m.render() } + +func (m *promptModel) render() string { // HideEntered: empty final frame so the masked value isn't left in // scrollback after the user presses Enter. if m.submitted && m.hideEntered { diff --git a/libs/cmdio/select.go b/libs/cmdio/select.go index 469e293f561..7d888de7b27 100644 --- a/libs/cmdio/select.go +++ b/libs/cmdio/select.go @@ -354,7 +354,9 @@ func (m *selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } -func (m *selectModel) View() string { +func (m *selectModel) View() string { return m.render() } + +func (m *selectModel) render() string { var b strings.Builder // After submission render only the Selected template; the post-quit diff --git a/libs/cmdio/spinner.go b/libs/cmdio/spinner.go index 974c673a76a..195f42f65bc 100644 --- a/libs/cmdio/spinner.go +++ b/libs/cmdio/spinner.go @@ -81,7 +81,9 @@ func (m spinnerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } -func (m spinnerModel) View() string { +func (m spinnerModel) View() string { return m.render() } + +func (m spinnerModel) render() string { if m.quitting { return "" } diff --git a/libs/tableview/tableview.go b/libs/tableview/tableview.go index d85ca1cb52c..4662f4b638e 100644 --- a/libs/tableview/tableview.go +++ b/libs/tableview/tableview.go @@ -343,7 +343,9 @@ func (m model) updateSearch(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } } -func (m model) View() string { +func (m model) View() string { return m.render() } + +func (m model) render() string { if !m.ready { return "Loading..." }