This repository was archived by the owner on Sep 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed
Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 11package core
22
33import (
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
1315type 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
1929func (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
7794func NewStatusCmp () tea.Model {
78- return & statusCmp {}
95+ return & statusCmp {
96+ messageTTL : 5 * time .Second ,
97+ }
7998}
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ func ReportError(err error) tea.Cmd {
1313}
1414
1515type (
16- InfoMsg string
17- ErrorMsg error
16+ InfoMsg string
17+ ErrorMsg error
18+ ClearStatusMsg struct {}
1819)
1920
2021func Clamp (v , low , high int ) int {
You can’t perform that action at this time.
0 commit comments