diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-09 00:06:43 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-09 00:06:43 -0500 |
| commit | b390b93e1c86f90c9044323d6a4fa7f59bafc4f0 (patch) | |
| tree | e9a9036af4eead3872ac3dfc9d3d8457cdd291de | |
| parent | 1a3cba38218d5652be1d8c1d4b165bf980c97831 (diff) | |
Ignore whitespace in lookups and new cards
| -rw-r--r-- | add.go | 2 | ||||
| -rw-r--r-- | ui.go | 3 |
2 files changed, 4 insertions, 1 deletions
@@ -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")) } @@ -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) { |
