1package util
2
3import (
4 "log/slog"
5 "time"
6
7 tea "github.com/charmbracelet/bubbletea/v2"
8)
9
10type Cursor interface {
11 Cursor() *tea.Cursor
12}
13
14type Model interface {
15 tea.Model
16 tea.ViewModel
17}
18
19func CmdHandler(msg tea.Msg) tea.Cmd {
20 return func() tea.Msg {
21 return msg
22 }
23}
24
25func ReportError(err error) tea.Cmd {
26 slog.Error("Error reported", "error", err)
27 return CmdHandler(InfoMsg{
28 Type: InfoTypeError,
29 Msg: err.Error(),
30 })
31}
32
33type InfoType int
34
35const (
36 InfoTypeInfo InfoType = iota
37 InfoTypeWarn
38 InfoTypeError
39)
40
41func ReportInfo(info string) tea.Cmd {
42 return CmdHandler(InfoMsg{
43 Type: InfoTypeInfo,
44 Msg: info,
45 })
46}
47
48func ReportWarn(warn string) tea.Cmd {
49 return CmdHandler(InfoMsg{
50 Type: InfoTypeWarn,
51 Msg: warn,
52 })
53}
54
55type (
56 InfoMsg struct {
57 Type InfoType
58 Msg string
59 TTL time.Duration
60 }
61 ClearStatusMsg struct{}
62)