diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-08 13:29:44 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-08 13:29:44 -0500 |
| commit | 882c41c7df91a8851e904caa85f9a8259ac44570 (patch) | |
| tree | ae506b70ee47a51cebd299b25d79f9c904d1d84b /ui.go | |
| parent | d30e386491024e3740ac27039cd6b0dd5bb15334 (diff) | |
Allow invoking with a word to look up
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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 { |
