@@ -1,6 +1,8 @@
1package core
1package core
4 tea "github.com/charmbracelet/bubbletea"
6 tea "github.com/charmbracelet/bubbletea"
5 "github.com/charmbracelet/lipgloss"
7 "github.com/charmbracelet/lipgloss"
6 "github.com/kujtimiihoxha/termai/internal/config"
8 "github.com/kujtimiihoxha/termai/internal/config"
@@ -11,9 +13,17 @@ import (
13type statusCmp struct {
15type statusCmp struct {
14− err error
16+ err error
15− info string
17+ info string
16− width int
18+ width int
19+ messageTTL time.Duration
22+// clearMessageCmd is a command that clears status messages after a timeout
23+func (m statusCmp) clearMessageCmd() tea.Cmd {
24+ return tea.Tick(m.messageTTL, func(time.Time) tea.Msg {
25+ return util.ClearStatusMsg{}
19func (m statusCmp) Init() tea.Cmd {
29func (m statusCmp) Init() tea.Cmd {
@@ -26,8 +36,15 @@ func (m statusCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
26 m.width = msg.Width
36 m.width = msg.Width
27 case util.ErrorMsg:
37 case util.ErrorMsg:
28 m.err = msg
38 m.err = msg
40+ return m, m.clearMessageCmd()
29 case util.InfoMsg:
41 case util.InfoMsg:
30 m.info = string(msg)
42 m.info = string(msg)
44+ return m, m.clearMessageCmd()
45+ case util.ClearStatusMsg:
32 return m, nil
49 return m, nil
@@ -75,5 +92,7 @@ func (m statusCmp) model() string {
77func NewStatusCmp() tea.Model {
94func NewStatusCmp() tea.Model {
78− return &statusCmp{}
95+ return &statusCmp{
96+ messageTTL: 5 * time.Second,