From 821c198fe6700a9e9e9eb07ab6922e7bde7f2bfb Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Mon, 25 Nov 2024 16:45:33 -0500 Subject: Accept initial color using -c flag (#14) --- internal/switcher/switcher.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/switcher') diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go index fce242c..ec5c47a 100644 --- a/internal/switcher/switcher.go +++ b/internal/switcher/switcher.go @@ -51,8 +51,29 @@ func (m *Model) Prev() int { return m.active } +func (m *Model) SetActive(i int) { + m.active = m.fixSel(i) +} + +func (m *Model) UpdatePicker(i int, c colors.ColorSpace) { + m.pickers[i].SetColor(c) +} + +func (m *Model) NewNotice(msg string) tea.Cmd { + return m.notices.New(msg) +} + 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)) + } + for _, p := range m.pickers { cmds = append(cmds, p.Init()) } -- cgit v1.2.3