Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit a1f6147

Browse files
kujtimiihoxhatermai
andcommitted
Add auto-removal of status bar messages after timeout
🤖 Generated with termai Co-Authored-By: termai <[email protected]>
1 parent b28c1e0 commit a1f6147

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

internal/tui/components/core/status.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package core
22

33
import (
4+
"time"
5+
46
tea "github.com/charmbracelet/bubbletea"
57
"github.com/charmbracelet/lipgloss"
68
"github.com/kujtimiihoxha/termai/internal/config"
@@ -11,9 +13,17 @@ import (
1113
)
1214

1315
type statusCmp struct {
14-
err error
15-
info string
16-
width int
16+
err error
17+
info string
18+
width int
19+
messageTTL time.Duration
20+
}
21+
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{}
26+
})
1727
}
1828

1929
func (m statusCmp) Init() tea.Cmd {
@@ -26,8 +36,15 @@ func (m statusCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2636
m.width = msg.Width
2737
case util.ErrorMsg:
2838
m.err = msg
39+
m.info = ""
40+
return m, m.clearMessageCmd()
2941
case util.InfoMsg:
3042
m.info = string(msg)
43+
m.err = nil
44+
return m, m.clearMessageCmd()
45+
case util.ClearStatusMsg:
46+
m.info = ""
47+
m.err = nil
3148
}
3249
return m, nil
3350
}
@@ -75,5 +92,7 @@ func (m statusCmp) model() string {
7592
}
7693

7794
func NewStatusCmp() tea.Model {
78-
return &statusCmp{}
95+
return &statusCmp{
96+
messageTTL: 5 * time.Second,
97+
}
7998
}

internal/tui/util/util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ func ReportError(err error) tea.Cmd {
1313
}
1414

1515
type (
16-
InfoMsg string
17-
ErrorMsg error
16+
InfoMsg string
17+
ErrorMsg error
18+
ClearStatusMsg struct{}
1819
)
1920

2021
func Clamp(v, low, high int) int {

0 commit comments

Comments
 (0)