diff --git a/Makefile b/Makefile
index eb08518ffbba68cbace6e59867f37074cb02adac..a04902b0aadb72c1913e793732b226f5bbe3c8d7 100644
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,7 @@ buid: ext
$(GO_BUILD) -o $(BIN) ./cmd/dict/main.go
run: ext
- $(GO_RUN) ./cmd/dict/main.go
-
+ $(GO_RUN) ./cmd/dict/main.go ui
import: ext
$(GO_RUN) ./cmd/dict/main.go import
diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go
index 82c0bc5fed899b86af453dc08e1d3b2909ac9501..b5f2f2fca941082410826eb92820fcb5b44172f8 100644
--- a/cmd/ui/ui.go
+++ b/cmd/ui/ui.go
@@ -21,13 +21,13 @@ Name: "ui",
Usage: "interactive dictionary",
Flags: []cli.Flag{
&cli.StringFlag{
- Name: "filename",
+ Name: "database",
Value: "main.dict",
Usage: "Dictionary database location",
},
},
Action: func(cCtx *cli.Context) error {
- name := cCtx.String("lang")
+ name := cCtx.String("database")
return Run(context.Background(), name)
},
}
@@ -87,8 +87,10 @@ return vs
})
input.SetDoneFunc(func(key tcell.Key) {
- textView.Clear()
- input.SetText("")
+ if key == tcell.KeyEscape {
+ textView.Clear()
+ input.SetText("")
+ }
})
grid := tview.NewGrid().
diff --git a/db/db.go b/db/db.go
index 746c30d2b2886716386f8794a339201479da9e24..b28dea2cb1aa9b02df7b1ab68295f21e6f36458e 100644
--- a/db/db.go
+++ b/db/db.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
+ "os"
"github.com/mattn/go-sqlite3"
)
@@ -42,9 +43,8 @@ func (d *DB) Migrate(ctx context.Context) error {
_, err := d.db.ExecContext(
ctx,
`CREATE VIRTUAL TABLE IF NOT EXISTS words USING fts5 (word, line);
- CREATE VIRTUAL TABLE IF NOT EXISTS words_terms USING fts4aux(words);
- CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1;
- `,
+ CREATE VIRTUAL TABLE IF NOT EXISTS words_vocab USING fts5vocab('words', 'row');
+ CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1;`,
)
return err
}
@@ -100,7 +100,7 @@ }
words = append(words, w)
}
- return words, err
+ return words, nil
}
@@ -119,8 +119,7 @@
func (d *DB) Consolidade(ctx context.Context) error {
_, err := d.db.ExecContext(
ctx,
- `INSERT INTO spell(word,rank)
- SELECT term, documents FROM words_terms WHERE col='*'`,
+ `INSERT INTO spell(word) SELECT term FROM words_vocab`,
)
if err != nil {
return err
@@ -139,6 +138,10 @@ return Copy(ctx, d.db, destDb)
}
func (d *DB) Restore(ctx context.Context, name string) error {
+ if _, err := os.Stat(name); err != nil {
+ return err
+ }
+
srcDb, err := sql.Open("sqlite3_with_extensions", name)
if err != nil {
return err