okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

dawntui: gallery of every screen state (registerShots) drawn as per-screen contact sheets4db295e

main
3.0 KiB82 linesraw
1package tui
2
3import (
4	"errors"
5
6	tea "charm.land/bubbletea/v2"
7)
8
9func init() {
10	enter := tea.KeyPressMsg{Code: tea.KeyEnter}
11	shiftEnter := tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModShift}
12	down := tea.KeyPressMsg{Code: tea.KeyDown}
13	typed := func(text string) []tea.Msg {
14		var keys []tea.Msg
15		for _, r := range text {
16			keys = append(keys, tea.KeyPressMsg{Code: r, Text: string(r)})
17		}
18		return keys
19	}
20	registerShots("extensions",
21		shotState{"list", extensionsShot(nil)},
22		shotState{"filtering", extensionsShot(nil, typed("bs")...)},
23		shotState{"no-match", extensionsShot(nil, typed("zzz")...)},
24		shotState{"quarantined", extensionsShot(nil, down, down, down)},
25		shotState{"confirm-global", extensionsShot(nil, enter)},
26		shotState{"confirm-session", extensionsShot(nil, shiftEnter)},
27		shotState{"confirm-follow-global", extensionsShot(nil, tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl})},
28		shotState{"saving", extensionsShot(nil, shiftEnter, enter)},
29		shotState{"save-failed", func(w, h int) string {
30			m := extensionsModel(w, h, nil)
31			m, _ = m.Update(shiftEnter)
32			m, _ = m.Update(enter)
33			m, _ = m.Update(extensionToggledMsg{Gen: m.Generation, Err: errors.New("daemon refused the change")})
34			return m.View()
35		}},
36		shotState{"notice", extensionsShot(func(m *ExtensionPickerModel) {
37			m.Notice = "Saved the global default. Reload sessions to apply it."
38		})},
39		shotState{"loading", func(w, h int) string {
40			m := NewExtensionPickerModel(nil, "s")
41			m.SetSize(w, h)
42			return m.View()
43		}},
44		shotState{"empty", func(w, h int) string {
45			m := NewExtensionPickerModel(nil, "s")
46			m.SetSize(w, h)
47			m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation})
48			return m.View()
49		}},
50		shotState{"load-failed", func(w, h int) string {
51			m := NewExtensionPickerModel(nil, "s")
52			m.SetSize(w, h)
53			m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation, Err: errors.New("daemon connection unavailable")})
54			return m.View()
55		}},
56	)
57}
58
59func extensionsModel(width, height int, setup func(*ExtensionPickerModel)) ExtensionPickerModel {
60	m := NewExtensionPickerModel(nil, "s")
61	m.SetSize(width, height)
62	m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation, Extensions: []ExtensionItem{
63		{Name: "view", Description: "show the model its changes as highlighted images", Enabled: true, Overridden: true, Plugins: []string{"tool"}, Tools: []string{"view_diff"}},
64		{Name: "bash", Description: "run shell commands", Enabled: true, GlobalEnabled: true, Plugins: []string{"tool", "context"}, Context: true},
65		{Name: "webhooks", Description: "signed inbound requests wake a session"},
66		{Name: "mcp", Description: "tool servers", GlobalEnabled: true, Quarantined: "failed to start"},
67	}})
68	if setup != nil {
69		setup(&m)
70	}
71	return m
72}
73
74func extensionsShot(setup func(*ExtensionPickerModel), keys ...tea.Msg) func(width, height int) string {
75	return func(width, height int) string {
76		m := extensionsModel(width, height, setup)
77		for _, key := range keys {
78			m, _ = m.Update(key)
79		}
80		return m.View()
81	}
82}