french-wiktionary-flashcards

Easily create Anki flashcards from Wiktionary data.
Log | Files | Refs | README

commit 38cd475b37026775c7d0d1ab825636bea5d304f4
parent 8e541e79647fc794cc0dc13378a7ab8bf1181a9d
Author: David Schlachter <t480-debian-git@schlachter.ca>
Date:   Fri, 25 Sep 2026 14:36:47 -0400

Wrap some long lines

Diffstat:
Mmain.go | 47++++++++++++++++++++++++++++++++++++++---------
Msetup.go | 5++++-
Mui.go | 45++++++++++++++++++++++++++++++++++++++-------
3 files changed, 80 insertions(+), 17 deletions(-)

diff --git a/main.go b/main.go @@ -14,26 +14,55 @@ import ( ) func main() { - rawDict := flag.String("rawDictionary", "raw-wiktextract-data.jsonl", "Path to the raw wiktionary data. You can get this by downloading and unzipping https://kaikki.org/frwiktionary/raw-wiktextract-data.jsonl.gz (for French).") - dict := flag.String("dictionary", "dictionary.sqlite3", "Path to the parsed dictionary data. This will be generated from rawDictionary.") - deckName := flag.String("deck", "", "Name of the deck where new Anki cards will be created.") - modelName := flag.String("model", "", "Name of the card type ('model') for new Anki cards.") - apiURL := flag.String("apiURL", "http://localhost:8765", "Base URL to access the anki-connect plugin API.") - initialWord := flag.String("initialWord", "", "Optional: first word to look up on program launch.") + rawDict := flag.String( + "rawDictionary", + "raw-wiktextract-data.jsonl", + "Path to the raw wiktionary data. You can get this by downloading and gunzipping https://kaikki.org/frwiktionary/raw-wiktextract-data.jsonl.gz (for French).", + ) + dict := flag.String( + "dictionary", + "dictionary.sqlite3", + "Path to the parsed dictionary data. This will be generated from rawDictionary.", + ) + deckName := flag.String( + "deck", + "", + "Name of the deck where new Anki cards will be created.", + ) + modelName := flag.String( + "model", + "", + "Name of the card type ('model') for new Anki cards.", + ) + apiURL := flag.String( + "apiURL", + "http://localhost:8765", + "Base URL to access the anki-connect plugin API.", + ) + initialWord := flag.String("initialWord", + "", + "Optional: first word to look up on program launch.", + ) flag.Parse() if *dict == "" { - log.Fatal("The -dictionary flag cannot be an empty string. (If not provided, it defaults to dictionary.sqlite3.)") + log.Fatal( + "The -dictionary flag cannot be empty. (Defaults to dictionary.sqlite3.)", + ) } if *rawDict == "" { - log.Fatal("The -rawDictionary flag cannot be an empty string. (If not provided, it defaults to aw-wiktextract-data.jsonl.)") + log.Fatal( + "The -rawDictionary flag cannot be empty. (Defaults to raw-wiktextract-data.jsonl.)", + ) } if *deckName == "" { log.Fatal("The -deck flag must be provided (name of the deck where Anki cards will be created).") } if *modelName == "" { - log.Fatal("The -model flag must be provided. This is the name of the card type ('model') for any Anki cards created by this program. This appears under 'Type' on the dialog for creating new cards in Anki.") + log.Fatal( + "The -model flag must be provided. This is the name of the card type ('model') for any Anki cards created by this program. This appears under 'Type' on the dialog for creating new cards in Anki.", + ) } db, err := sql.Open("sqlite3", *dict) diff --git a/setup.go b/setup.go @@ -224,7 +224,10 @@ func populateDictionary(dp *dictionaryPopulator) tea.Cmd { example = s.Examples[0].Text } sense := strings.Join(s.Glosses, "; ") - entry.Senses = append(entry.Senses, SenseForDictionaryEntry{Sense: sense, Example: example}) + entry.Senses = append( + entry.Senses, + SenseForDictionaryEntry{Sense: sense, Example: example}, + ) } formattedDefinition := strings.Builder{} diff --git a/ui.go b/ui.go @@ -48,7 +48,11 @@ type ( populatingDictionaryMsg *dictionaryPopulator ) -func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel, rawDictionary, firstWord string) model { +func initialModel( + c *http.Client, + db *sql.DB, + apiURL, ankiDeck, ankiModel, rawDictionary, firstWord string, +) model { input := textinput.New() input.Placeholder = "" input.Focus() @@ -115,7 +119,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.dictionaryReady = true m.statusString = "" if m.currentWord != "" { - textPickerLongerCmds = append(textPickerLongerCmds, lookupWord(m.db, m.currentWord)) + textPickerLongerCmds = append( + textPickerLongerCmds, + lookupWord(m.db, m.currentWord), + ) } } case populatingDictionaryMsg: @@ -124,7 +131,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case definitionMsg: m.currentDefinition = string(msg) m.err = nil - m.definitionViewport.SetContent(formatDefinitionForDisplay(m.p, m.currentDefinition, m.definitionViewport.Width)) + m.definitionViewport.SetContent( + formatDefinitionForDisplay( + m.p, + m.currentDefinition, + m.definitionViewport.Width, + ), + ) return m, nil case wordAddedMsg: m.statusString = fmt.Sprintf("✅ Added '%s' to Anki", string(msg)) @@ -143,7 +156,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.definitionViewport.Height = msg.Height - headerHeight m.definitionViewport.SetContent( - formatDefinitionForDisplay(m.p, m.currentDefinition, m.definitionViewport.Width), + formatDefinitionForDisplay( + m.p, + m.currentDefinition, + m.definitionViewport.Width, + ), ) case tea.KeyMsg: switch msg.Type { @@ -156,7 +173,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.wordInput.SetValue("") m.definitionViewport.SetContent("") case tea.KeyEnter: - return m, addCard(m.c, m.apiURL, m.ankiDeck, m.ankiModel, m.currentWord, m.currentDefinition) + return m, addCard( + m.c, + m.apiURL, + m.ankiDeck, + m.ankiModel, + m.currentWord, + m.currentDefinition, + ) } case errMsg: @@ -166,7 +190,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.wordInput.Value() != m.currentWord { m.currentWord = m.wordInput.Value() - textPickerLongerCmds = append(textPickerLongerCmds, lookupWord(m.db, m.currentWord)) + textPickerLongerCmds = append( + textPickerLongerCmds, + lookupWord(m.db, m.currentWord), + ) } var vpCmd tea.Cmd @@ -198,7 +225,11 @@ func (m model) View() string { return fmt.Sprintf("\nPreparing dictionary...\n\n%s\n\n", m.importProgress.ViewAs(m.importFraction)) } -func formatDefinitionForDisplay(policy bluemonday.Policy, definition string, maxWidth int) string { +func formatDefinitionForDisplay( + policy bluemonday.Policy, + definition string, + maxWidth int, +) string { // Add a hyphen to the start of each definition str := strings.ReplaceAll(definition, "<li class=sense>", "<li class=sense>- ")