diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-11 23:55:52 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-11 23:55:52 -0500 |
| commit | c7e2672b0083eb81ed4d494e1f90b30e0a86c7d9 (patch) | |
| tree | ce195758813eee8b3753c172b10b061c1fd5b155 /ui.go | |
| parent | 068ef1f9ac1fe551b97b9d5aec224369ebe015fd (diff) | |
Provide basic setup status through UI
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -19,6 +19,7 @@ type model struct { db *sql.DB c *http.Client p bluemonday.Policy + dp dictionaryPopulator wordInput textinput.Model definitionViewport viewport.Model @@ -37,10 +38,11 @@ type model struct { } type ( - errMsg error - definitionMsg string - wordAddedMsg string - isDBEmptyMsg bool + errMsg error + definitionMsg string + wordAddedMsg string + isDictionaryEmptyMsg bool + populatingDictionaryMsg *dictionaryPopulator ) func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel, rawDictionary, firstWord string) model { @@ -66,10 +68,17 @@ func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel, rawDi ), } + dp := dictionaryPopulator{ + db: db, + rawDictionaryPath: rawDictionary, + langCode: "fr", + } + return model{ db: db, c: c, p: *bluemonday.StrictPolicy(), + dp: dp, wordInput: input, definitionViewport: textbox, @@ -95,16 +104,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var textPickerLongerCmds []tea.Cmd switch msg := msg.(type) { - case isDBEmptyMsg: - if bool(msg) { - // set up the database - return m, populateDictionary(m.rawDictionaryPath, m.db) - } else { + case isDictionaryEmptyMsg: + if bool(msg) { // We need to populate the dictionary + return m, setupPopulator(&m.dp) + } else { // The dictionary is ready m.dictionaryReady = true + m.statusString = "" if m.currentWord != "" { textPickerLongerCmds = append(textPickerLongerCmds, lookupWord(m.db, m.currentWord)) } } + case populatingDictionaryMsg: + m.statusString = fmt.Sprintf("Currently on line %d...", msg.currentLine) + return m, populateDictionary((*dictionaryPopulator)(msg)) case definitionMsg: m.currentDefinition = string(msg) m.err = nil @@ -170,7 +182,7 @@ func (m model) View() string { if m.err != nil { return fmt.Sprintf("Failed to load dictionary! Error:\n\n%s\n\nExit with Control-C.\n", m.err) } - return fmt.Sprintln("Preparing dictionary...") + return fmt.Sprintf("Preparing dictionary...\n\n%s\n\n", m.statusString) } func formatDefinitionForDisplay(policy bluemonday.Policy, definition string, maxWidth int) string { |
