summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-09 00:06:43 -0500
committerDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-09 00:06:43 -0500
commitb390b93e1c86f90c9044323d6a4fa7f59bafc4f0 (patch)
treee9a9036af4eead3872ac3dfc9d3d8457cdd291de
parent1a3cba38218d5652be1d8c1d4b165bf980c97831 (diff)
Ignore whitespace in lookups and new cards
-rw-r--r--add.go2
-rw-r--r--ui.go3
2 files changed, 4 insertions, 1 deletions
diff --git a/add.go b/add.go
index 5116c86..9d25288 100644
--- a/add.go
+++ b/add.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
+ "strings"
tea "github.com/charmbracelet/bubbletea"
)
@@ -43,6 +44,7 @@ type options struct {
func addCard(c *http.Client, apiURL, deckName, modelName, front, back string) tea.Cmd {
return func() tea.Msg {
+ front = strings.TrimSpace(front)
if back == "" {
return errMsg(errors.New("definition is blank"))
}
diff --git a/ui.go b/ui.go
index 62de3cd..300fb64 100644
--- a/ui.go
+++ b/ui.go
@@ -73,8 +73,9 @@ func (m model) Init() tea.Cmd {
func lookupWord(db *sql.DB, word string) tea.Cmd {
return func() tea.Msg {
- var definition string
+ 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)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {