From 882c41c7df91a8851e904caa85f9a8259ac44570 Mon Sep 17 00:00:00 2001 From: David Schlachter Date: Thu, 8 Jan 2026 13:29:44 -0500 Subject: Allow invoking with a word to look up --- ui.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ui.go') diff --git a/ui.go b/ui.go index 6b3f8e9..62de3cd 100644 --- a/ui.go +++ b/ui.go @@ -36,7 +36,7 @@ type ( wordAddedMsg string ) -func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel string) model { +func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel, firstWord string) model { ti := textinput.New() ti.Placeholder = "" ti.Focus() @@ -44,6 +44,10 @@ func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel string ti.Width = 36 vp := viewport.New(80, 30) + if firstWord != "" { + ti.SetValue(firstWord) + } + return model{ wordInput: ti, err: nil, @@ -55,11 +59,16 @@ func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel string ankiDeck: ankiDeck, ankiModel: ankiModel, apiURL: apiURL, + currentWord: firstWord, } } func (m model) Init() tea.Cmd { - return textinput.Blink + cmds := []tea.Cmd{textinput.Blink} + if m.currentWord != "" { + cmds = append(cmds, lookupWord(m.db, m.currentWord)) + } + return tea.Batch(cmds...) } func lookupWord(db *sql.DB, word string) tea.Cmd { -- cgit v1.2.3