summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-11-25 17:03:24 -0500
committerGitHub <noreply@github.com>2024-11-25 17:03:24 -0500
commit98e089b8e5675fb6b1a91132af090947423f4503 (patch)
tree31f44c1e8eff739d1ccf2000a5e72ec0f97bbb9b
parent4b54e4449052df210af33f679001727a9c12b7d4 (diff)
fix: initial color notice didn't expire (#15)
* Accept initial color using -c flag * fix: Initial color notice expiry * Inform user of detected initial color
-rw-r--r--internal/notices/notices.go7
-rw-r--r--internal/switcher/switcher.go10
-rw-r--r--main.go1
3 files changed, 12 insertions, 6 deletions
diff --git a/internal/notices/notices.go b/internal/notices/notices.go
index 4fbd807..40b5d1f 100644
--- a/internal/notices/notices.go
+++ b/internal/notices/notices.go
@@ -58,3 +58,10 @@ func (m Model) New(msg string) tea.Cmd {
return NoticeExpiryMsg(uuid)
}
}
+
+func (m Model) Reset(uuid string) tea.Cmd {
+ return func() tea.Msg {
+ time.Sleep(expiryDelay * time.Second)
+ return NoticeExpiryMsg(uuid)
+ }
+}
diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go
index ec5c47a..860bf81 100644
--- a/internal/switcher/switcher.go
+++ b/internal/switcher/switcher.go
@@ -66,12 +66,10 @@ func (m *Model) NewNotice(msg string) tea.Cmd {
func (m Model) Init() tea.Cmd {
cmds := []tea.Cmd{}
- // Make a backup of notices received before the program starts
- // then reinitialize them with a proper expiration time.
- noticeBackup := m.notices.Notices
- m.notices = notices.New()
- for _, v := range noticeBackup {
- cmds = append(cmds, m.NewNotice(v))
+ // The NoticeExpiryMsg is never sent to bubbletea by a tea.Cmd for the initial notices
+ // That's why we need to manually reset them here. Otherwise, they would never expire.
+ for k := range m.notices.Notices {
+ cmds = append(cmds, m.notices.Reset(k))
}
for _, p := range m.pickers {
diff --git a/main.go b/main.go
index 4f61c75..a7ae880 100644
--- a/main.go
+++ b/main.go
@@ -50,6 +50,7 @@ func AppAction(ctx *cli.Context) error {
sw.UpdatePicker(2, pc)
sw.SetActive(2)
}
+ sw.NewNotice("Color set to " + colorStr)
}
}