summaryrefslogtreecommitdiff
path: root/ui.go
diff options
context:
space:
mode:
authorDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-08 13:29:44 -0500
committerDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-08 13:29:44 -0500
commit882c41c7df91a8851e904caa85f9a8259ac44570 (patch)
treeae506b70ee47a51cebd299b25d79f9c904d1d84b /ui.go
parentd30e386491024e3740ac27039cd6b0dd5bb15334 (diff)
Allow invoking with a word to look up
Diffstat (limited to 'ui.go')
-rw-r--r--ui.go13
1 files changed, 11 insertions, 2 deletions
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 {