on main help sign in
Add auto-removal of status bar messages after timeout

๐Ÿค– Generated with termai Co-Authored-By: termai <noreply@termai.io>

commita1f6147506af1f98e5dfa670fc83fa45c2249842 authorKujtim Hoxha <kujtimii.h@gmail.com> dateFri 4 Apr 2025, 14:52 (2 years ago) parentb28c1e0
2 files changed+26โˆ’6
internal/tui/components/core/status.go+23โˆ’4 internal/tui/util/util.go+3โˆ’2
internal/tui/components/core/status.go+23โˆ’4
@@ -1,6 +1,8 @@
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}
internal/tui/util/util.go+3โˆ’2
@@ -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 {