Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879package tui
import ( "albedo/cli/internal/daemon" "os" "strings" "unicode"
"github.com/charmbracelet/x/ansi")
// titleMode is how the client names its terminal window, read once from// ALBEDO_WINDOW_TITLE. It is off unless asked for: session names can be// private, and a title shows in taskbars, tmux status lines and screen shares.// "name" (or on, 1, true, yes) names the active session; "id" also appends the// full session ID so a window manager script can find the window that holds it.type titleMode int
const ( titleOff titleMode = iota titleName titleWithID)
func windowTitleMode() titleMode { switch strings.ToLower(strings.TrimSpace(os.Getenv("ALBEDO_WINDOW_TITLE"))) { case "name", "on", "1", "true", "yes": return titleName case "id": return titleWithID default: return titleOff }}
// windowTitleNameLimit caps the session name in runes; the ID is never cut,// since a truncated ID would match the wrong window.const windowTitleNameLimit = 120
func windowTitle(mode titleMode, session *daemon.Session) string { if mode == titleOff { return "" } if session == nil { return "albedo" } name := titleText(session.Title, windowTitleNameLimit) if name == "" { name = "albedo" } else { name += " — albedo" } if mode == titleWithID { if id := titleText(session.ID, 0); id != "" { name += " [" + id + "]" } } return name}
// titleText makes untrusted text safe for an OSC title payload: escape// sequences are stripped, then control and format runes (bidi overrides// included) are dropped. A zero limit keeps every rune.func titleText(text string, limit int) string { var b strings.Builder n := 0 for _, r := range ansi.Strip(text) { if !unicode.IsPrint(r) { continue } b.WriteRune(r) n++ if limit > 0 && n == limit { break } } return strings.TrimSpace(b.String())}