Something went wrong. Try again.
small gleam coding and (not yet) persistent agent daemon with a detachable cli forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586package tui
import ( "strings"
"albedo/cli/internal/daemon"
tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi")
// termsBox is the box that warns, before a sign-in or before the first// message on a profile that uses one, that the provider's terms forbid that// sign-in outside its own apps. Enter goes on, esc backs out, and every other// key is ignored.type termsBox struct { terms daemon.Terms title string // back and proceed are what esc and enter do. back, proceed string // once says the box will not come back after enter. once bool}
func signInTerms(terms daemon.Terms) *termsBox { return &termsBox{terms: terms, title: "/login", back: "back", proceed: "sign in anyway"}}
func messageTerms(terms daemon.Terms) *termsBox { return &termsBox{terms: terms, title: "first message", back: "edit", proceed: "send", once: true}}
// key settles a key press: proceed on enter, closed on esc.func (b *termsBox) key(msg tea.KeyPressMsg) (proceed, closed bool) { switch msg.String() { case "enter": return true, true case "esc", "ctrl+c": return false, true } return false, false}
// view draws the box at most height rows tall; a short screen loses the// blank lines first.func (b *termsBox) view(width, height int) []string { outer := cdBoxWidth(width) inner := outer - 6 box := b.draw(inner, false) if len(box)+2 > height { box = b.draw(inner, true) } return cdFrame(b.title, box, outer)}
func (b *termsBox) draw(inner int, tight bool) []string { var body []string gap := func() { if !tight { body = append(body, "") } } wrap := func(render func(string) string, text string) { for line := range strings.SplitSeq(ansi.Wrap(text, inner, " "), "\n") { body = append(body, render(line)) } } gap() headline := DefaultStyles.Warning.Bold(true) wrap(func(s string) string { return s }, b.terms.About) wrap(func(s string) string { return headline.Render(s) }, b.terms.Headline) for _, paragraph := range b.terms.Paragraphs { gap() wrap(func(s string) string { return DefaultStyles.Muted.Render(s) }, paragraph) } if b.once { gap() wrap(func(s string) string { return DefaultStyles.Faint.Render(s) }, "albedo shows this once per provider.") } gap() hints := cdKeys([]hint{{"esc", b.back}, {"enter", b.proceed}}) body = append(body, strings.Repeat(" ", max(0, inner-ansi.StringWidth(hints)))+hints) gap() return body}