Skip to content

Commit 50ff20b

Browse files
pieternIsaac
andcommitted
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 <no-reply@databricks.com>
1 parent c3a1676 commit 50ff20b

9 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎cmd/air/list_tui.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ func (m listModel) clampedOffset() int {
335335
return max(offset, 0)
336336
}
337337

338-
func (m listModel) View() string {
338+
func (m listModel) View() string { return m.render() }
339+
340+
func (m listModel) render() string {
339341
if m.mode == modeDetail {
340342
faint := m.styles.r.NewStyle().Foreground(colN7)
341343
lines := []string{m.detailTitle}

‎cmd/apps/init.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func promptForPluginsAndDeps(ctx context.Context, m *manifest.Manifest, preSelec
679679
// asks per resource that can be accessed on behalf of the user.
680680
// Resources that cannot are listed as info and resolve to sp.
681681
// Returns a map of resource key to auth mode, or nil if nothing needs to be asked.
682-
func promptForAuthModes(ctx context.Context, resources []manifest.Resource, theme *huh.Theme) (map[string]string, error) {
682+
func promptForAuthModes(ctx context.Context, resources []manifest.Resource, theme prompt.Theme) (map[string]string, error) {
683683
var capable []manifest.Resource
684684
for _, r := range resources {
685685
if r.Scope != "" && !r.AppOnly {
@@ -751,7 +751,7 @@ func authModeLabel(mode string) string {
751751
// promptForResource prompts the user for a resource value.
752752
// Returns a map of value keys to values. For single-field resources the key is "resource_key.field".
753753
// For multi-field resources, keys use "resource_key.field_name".
754-
func promptForResource(ctx context.Context, r manifest.Resource, theme *huh.Theme, required bool) (map[string]string, error) {
754+
func promptForResource(ctx context.Context, r manifest.Resource, theme prompt.Theme, required bool) (map[string]string, error) {
755755
if fn, ok := prompt.GetPromptFunc(r.Type); ok {
756756
if !required {
757757
var configure bool

‎libs/apps/prompt/prompt.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ var (
3737
colorDimmedDark cmdio.Color = lipgloss.Color("#52525B")
3838
)
3939

40+
// Theme is the huh theme handed to appkit prompt forms and fields.
41+
type Theme = *huh.Theme
42+
4043
// AppkitTheme returns a custom theme for appkit prompts.
41-
func AppkitTheme() *huh.Theme {
42-
return appkitTheme(cmdio.HasDarkBackground())
44+
func AppkitTheme() Theme {
45+
return appkitStyles(cmdio.HasDarkBackground())
4346
}
4447

45-
// appkitTheme builds the theme for a known background, matching the shape of
46-
// huh v2's ThemeFunc.
47-
func appkitTheme(isDark bool) *huh.Theme {
48+
// appkitStyles builds the appkit styles on top of huh's base theme for a known
49+
// background, matching the shape of huh v2's ThemeFunc.
50+
func appkitStyles(isDark bool) *huh.Theme {
4851
lightDark := cmdio.LightDark(isDark)
4952
t := huh.ThemeBase()
5053

‎libs/apps/prompt/prompt_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,6 @@ func TestListSystemAIModelServicesWithoutAccess(t *testing.T) {
557557
}
558558

559559
func TestAppkitThemeDimmedButtonFollowsBackground(t *testing.T) {
560-
assert.Equal(t, colorDimmedDark, appkitTheme(true).Focused.BlurredButton.GetForeground())
561-
assert.Equal(t, colorDimmedLight, appkitTheme(false).Focused.BlurredButton.GetForeground())
560+
assert.Equal(t, colorDimmedDark, appkitStyles(true).Focused.BlurredButton.GetForeground())
561+
assert.Equal(t, colorDimmedLight, appkitStyles(false).Focused.BlurredButton.GetForeground())
562562
}

‎libs/cmdio/pager.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ func (m *pagerModel[T]) startDrain() tea.Cmd {
230230
return m.fetch(m.pageSize, m.limit, m.total)
231231
}
232232

233-
func (m *pagerModel[T]) View() string {
233+
func (m *pagerModel[T]) View() string { return m.render() }
234+
235+
func (m *pagerModel[T]) render() string {
234236
switch {
235237
case m.iterDone || m.err != nil:
236238
return ""

‎libs/cmdio/prompt.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ func (m *promptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
204204
return m, nil
205205
}
206206

207-
func (m *promptModel) View() string {
207+
func (m *promptModel) View() string { return m.render() }
208+
209+
func (m *promptModel) render() string {
208210
// HideEntered: empty final frame so the masked value isn't left in
209211
// scrollback after the user presses Enter.
210212
if m.submitted && m.hideEntered {

‎libs/cmdio/select.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ func (m *selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
354354
return m, nil
355355
}
356356

357-
func (m *selectModel) View() string {
357+
func (m *selectModel) View() string { return m.render() }
358+
359+
func (m *selectModel) render() string {
358360
var b strings.Builder
359361

360362
// After submission render only the Selected template; the post-quit

‎libs/cmdio/spinner.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ func (m spinnerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8181
}
8282
}
8383

84-
func (m spinnerModel) View() string {
84+
func (m spinnerModel) View() string { return m.render() }
85+
86+
func (m spinnerModel) render() string {
8587
if m.quitting {
8688
return ""
8789
}

‎libs/tableview/tableview.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ func (m model) updateSearch(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
343343
}
344344
}
345345

346-
func (m model) View() string {
346+
func (m model) View() string { return m.render() }
347+
348+
func (m model) render() string {
347349
if !m.ready {
348350
return "Loading..."
349351
}

0 commit comments

Comments
 (0)