summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-04 14:52:30 +0200
committerKujtim Hoxha <[email protected]>2025-04-04 14:52:30 +0200
commita1f6147506af1f98e5dfa670fc83fa45c2249842 (patch)
treed6538a529b848c3a94a9ff58cf0e496ddabbbd7a
parentb28c1e0c03dbf12bf428f19214b10f4925c229fa (diff)
downloadopencode-a1f6147506af1f98e5dfa670fc83fa45c2249842.tar.gz
opencode-a1f6147506af1f98e5dfa670fc83fa45c2249842.zip
Add auto-removal of status bar messages after timeout
🤖 Generated with termai Co-Authored-By: termai <[email protected]>
-rw-r--r--internal/tui/components/core/status.go27
-rw-r--r--internal/tui/util/util.go5
2 files changed, 26 insertions, 6 deletions
diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go
index cd9dc55a0..bd3629319 100644
--- a/internal/tui/components/core/status.go
+++ b/internal/tui/components/core/status.go
@@ -1,6 +1,8 @@
package core
import (
+ "time"
+
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/kujtimiihoxha/termai/internal/config"
@@ -11,9 +13,17 @@ import (
)
type statusCmp struct {
- err error
- info string
- width int
+ err error
+ info string
+ width int
+ messageTTL time.Duration
+}
+
+// clearMessageCmd is a command that clears status messages after a timeout
+func (m statusCmp) clearMessageCmd() tea.Cmd {
+ return tea.Tick(m.messageTTL, func(time.Time) tea.Msg {
+ return util.ClearStatusMsg{}
+ })
}
func (m statusCmp) Init() tea.Cmd {
@@ -26,8 +36,15 @@ func (m statusCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.width = msg.Width
case util.ErrorMsg:
m.err = msg
+ m.info = ""
+ return m, m.clearMessageCmd()
case util.InfoMsg:
m.info = string(msg)
+ m.err = nil
+ return m, m.clearMessageCmd()
+ case util.ClearStatusMsg:
+ m.info = ""
+ m.err = nil
}
return m, nil
}
@@ -75,5 +92,7 @@ func (m statusCmp) model() string {
}
func NewStatusCmp() tea.Model {
- return &statusCmp{}
+ return &statusCmp{
+ messageTTL: 5 * time.Second,
+ }
}
diff --git a/internal/tui/util/util.go b/internal/tui/util/util.go
index fa3782843..f6cf20d60 100644
--- a/internal/tui/util/util.go
+++ b/internal/tui/util/util.go
@@ -13,8 +13,9 @@ func ReportError(err error) tea.Cmd {
}
type (
- InfoMsg string
- ErrorMsg error
+ InfoMsg string
+ ErrorMsg error
+ ClearStatusMsg struct{}
)
func Clamp(v, low, high int) int {