okami.mom/albedo

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

dawntui: replace the generic /quota page with a screen of latest limits, bars and per-limit trails8e3e173

main
1.6 KiB65 linesraw
1package tui
2
3import (
4	"regexp"
5	"strings"
6
7	tea "charm.land/bubbletea/v2"
8)
9
10// Private APC marks describe rows for selection and clicks, not the terminal.
11// Ultraviolet preserves APC payloads, and Terminal.app prints unknown ones.
12var privateRowMarks = regexp.MustCompile(`\x1b_albedo:[^\x1b]*\x1b\\`)
13
14// View captures the mouse only in chat, where it scrolls and selects; every
15// other screen leaves it to the terminal.
16func (m *AppModel) View() tea.View {
17	v := tea.NewView(privateRowMarks.ReplaceAllString(m.content(), ""))
18	v.MouseMode = tea.MouseModeNone
19	if m.State == AppStateChat {
20		v.MouseMode = tea.MouseModeCellMotion
21	}
22	return v
23}
24
25func (m *AppModel) content() string {
26	switch m.State {
27	case AppStateChat:
28		return m.Chat.View()
29	case AppStateSessionPicker:
30		var b strings.Builder
31		for _, n := range m.Notices {
32			style := DefaultStyles.Faint
33			if n.Error {
34				style = DefaultStyles.Error
35			}
36			b.WriteString(style.Render(n.Message))
37			b.WriteByte('\n')
38		}
39		return b.String() + m.SessionPicker.View()
40	case AppStateModelPicker:
41		return m.ModelPicker.View()
42	case AppStateExtensionPicker:
43		return m.ExtensionPicker.View()
44	case AppStateTreePicker:
45		return m.TreePicker.View()
46	case AppStateContextInspector:
47		return m.ContextInspector.View()
48	case AppStatePageView:
49		return m.PageView.View()
50	case AppStateCapabilityPage:
51		return m.CapabilityPage.View()
52	case AppStateWebhooksPage:
53		return m.WebhooksPage.View()
54	case AppStateAgents:
55		return m.Agents.View()
56	case AppStateFolderPicker:
57		return m.FolderPicker.View()
58	case AppStateLogin:
59		return m.Login.View()
60	case AppStateQuota:
61		return m.Quota.View()
62	default:
63		return ""
64	}
65}