package util import ( "log/slog" "time" tea "github.com/charmbracelet/bubbletea/v2" ) type Cursor interface { Cursor() *tea.Cursor } type Model interface { Init() tea.Cmd Update(tea.Msg) (Model, tea.Cmd) View() string } func CmdHandler(msg tea.Msg) tea.Cmd { return func() tea.Msg { return msg } } func ReportError(err error) tea.Cmd { slog.Error("Error reported", "error", err) return CmdHandler(InfoMsg{ Type: InfoTypeError, Msg: err.Error(), }) } type InfoType int const ( InfoTypeInfo InfoType = iota InfoTypeWarn InfoTypeError ) func ReportInfo(info string) tea.Cmd { return CmdHandler(InfoMsg{ Type: InfoTypeInfo, Msg: info, }) } func ReportWarn(warn string) tea.Cmd { return CmdHandler(InfoMsg{ Type: InfoTypeWarn, Msg: warn, }) } type ( InfoMsg struct { Type InfoType Msg string TTL time.Duration } ClearStatusMsg struct{} )