summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--ui.go20
2 files changed, 20 insertions, 6 deletions
diff --git a/README.md b/README.md
index 7066ce9..caed43f 100644
--- a/README.md
+++ b/README.md
@@ -83,8 +83,6 @@ Usage of french-wiktionary-flashcards:
# TODO
-- combine definitions for identical words (e.g. accroire, n & v). Or, we could
- expose them through the UI and, e.g. allow the user to tab between them.
- allow setting the language for initial processing, so that we could support
languages other than French
- general code cleanup & organization
@@ -99,6 +97,10 @@ Usage of french-wiktionary-flashcards:
with interactive options to choose the language and such.
- provide history (scrollback) of words looked up, to make it easier to switch
between definitions
+- definitions for different parts of speech could be more clearly separated in
+ the preview window. I think it's best to have all the different senses
+ combined onto one card, but it could still be interesting to allow the user to
+ scroll between them.
- store data in sqlite with more structure to make it easier to customize
the format of definitions on cards
- figure out some way to customize the names of the fields on the flashcards \ No newline at end of file
diff --git a/ui.go b/ui.go
index 3c4dbb7..c41d6f2 100644
--- a/ui.go
+++ b/ui.go
@@ -87,16 +87,28 @@ func (m model) Init() tea.Cmd {
func lookupWord(db *sql.DB, word string) tea.Cmd {
return func() tea.Msg {
word = strings.TrimSpace(word) // remove leading / trailing whitespace
- row := db.QueryRow(`select definition from words where word = ? limit 1`, word)
- var definition string
- err := row.Scan(&definition)
+ rows, err := db.Query(`select definition from words where word = ?`, word)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return definitionMsg("")
}
return errMsg(fmt.Errorf("looking up '%s': %s", word, err))
}
- return definitionMsg(definition)
+ defer rows.Close()
+ var combinedDefinition []string
+ for rows.Next() {
+ var definition string
+ err = rows.Scan(&definition)
+ if err != nil {
+ return errMsg(fmt.Errorf("looking up '%s': %s", word, err))
+ }
+ combinedDefinition = append(combinedDefinition, definition)
+ }
+ if err := rows.Err(); err != nil {
+ return errMsg(fmt.Errorf("looking up '%s': %s", word, err))
+ }
+
+ return definitionMsg(strings.Join(combinedDefinition, "\n\n"))
}
}