summaryrefslogtreecommitdiff
path: root/ui.go
diff options
context:
space:
mode:
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 {