on 94de6bc help sign in
65 lines 910 B history raw
1package util
3import (
4 "log/slog"
5 "time"
7 tea "charm.land/bubbletea/v2"
8)
10type Cursor interface {
11 Cursor() *tea.Cursor
14type Model interface {
15 Init() tea.Cmd
16 Update(tea.Msg) (Model, tea.Cmd)
17 View() string
20func CmdHandler(msg tea.Msg) tea.Cmd {
21 return func() tea.Msg {
22 return msg
23 }
26func ReportError(err error) tea.Cmd {
27 slog.Error("Error reported", "error", err)
28 return CmdHandler(InfoMsg{
29 Type: InfoTypeError,
30 Msg: err.Error(),
31 })
34type InfoType int
36const (
37 InfoTypeInfo InfoType = iota
38 InfoTypeSuccess
39 InfoTypeWarn
40 InfoTypeError
41 InfoTypeUpdate
44func ReportInfo(info string) tea.Cmd {
45 return CmdHandler(InfoMsg{
46 Type: InfoTypeInfo,
47 Msg: info,
48 })
51func ReportWarn(warn string) tea.Cmd {
52 return CmdHandler(InfoMsg{
53 Type: InfoTypeWarn,
54 Msg: warn,
55 })
58type (
59 InfoMsg struct {
60 Type InfoType
61 Msg string
62 TTL time.Duration
63 }
64 ClearStatusMsg struct{}