aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile31
-rw-r--r--README.md78
-rw-r--r--VERSION1
-rw-r--r--cmd/dict/main.go15
-rw-r--r--db/db.go4
5 files changed, 123 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 8190661..de3668f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,23 @@
-BIN?=bin/dict
+VERSION?=$(shell cat VERSION)
+BIN?=dict
+PREFIX?=/usr/local
+BINDIR?=$(PREFIX)/bin
+SHAREDIR ?= $(PREFIX)/share/$(BIN)
+OUT=./bin/$(BIN)
+EXT=./ext/libsqlite3ext.so
+
+GO_LDFLAGS:= -s -w
+GO_LDFLAGS+= -X main.Version=$(VERSION)
+GO_LDFLAGS+= -X git.gabrielgio.me/dict/db.LibPath=$(SHAREDIR)/libsqlite3ext
GO_BUILD=go build -v --tags "fts5"
GO_RUN=go run -v --tags "fts5"
-buid: ext
- $(GO_BUILD) -o $(BIN) ./cmd/dict/main.go
+build: ext
+ $(GO_BUILD) -ldflags "$(GO_LDFLAGS)" -o $(OUT) ./cmd/dict/main.go
+
+install:
+ install -Dm755 $(OUT) $(BINDIR)/$(BIN)
+ install -Dm644 $(EXT) $(SHAREDIR)/libsqlite3ext.so
run: ext
$(GO_RUN) ./cmd/dict/main.go ui
@@ -14,7 +28,14 @@ import: ext
serve: ext
$(GO_RUN) ./cmd/dict/main.go serve
-ext:
- gcc -shared -o ext/libsqlite3ext.so -fPIC ext/spellfix.c
+version: ext
+ $(GO_RUN) ./cmd/dict/main.go version
+
+uninstall:
+ rm $(BINDIR)/$(BIN)
+ rm $(SHAREDIR)/libsqlite3ext.so
+
.PHONY: ext
+ext:
+ gcc -shared -o ext/libsqlite3ext.so -fPIC ext/spellfix.c
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f5faf7d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,78 @@
+# Iterative dictionary
+
+The goal is to provide a frictionless dictionary searching experience: you type
+and the words show up on your prompt. Not need to wait a http request to go
+through.
+
+As of right now, dict just provides a thin layer on top of sqlite's fts5[^1]
+virtual table with support of spellfix[^2] for word suggestion.
+
+The whole database is loaded in memory for faster search and import process,
+which means that this application will consume substantial amounts of memory.
+On DE-EN dictionary, for example, it uses ~300MB, more then dict.cc tab on
+firefox (but less the most electron application out there)
+
+# Compiling
+
+You will need go, gcc and sqlite-dev, then you can just run
+
+```sh
+make
+```
+
+For development you can run:
+
+```sh
+make run # run the ui with default values
+make import # run the importer with default values
+make version # run the version command
+```
+
+# Installing
+
+To install locally you may run:
+
+```sh
+PREFIX=$(HOME)/.local make install
+```
+
+Or for a system wide istall:
+
+```sh
+sudo make install
+```
+
+# Usage
+
+To run the importer you will need to download dict.cc dictionary.
+First go to its request page[^3] and select your dictionary of choice.
+Once you download and unzip run the following command:
+
+```sh
+dict import --input dict.txt --output main.dict
+```
+
+Once the import process is complete[4] you can run the ui.
+
+```sh
+dict ui --database main.dict
+```
+
+# TODO
+
+- On disk operation: to reduce memory footprint we can read from the disk. We
+ would need to remove the instance response, since that is not possible
+ reading from the disk.
+- Better coloring on the list.
+- Better default path for sqlite database making use of XDG variables.
+- [optional] Multi dictionary support. Support more than one dict at once.
+- Async response. Even though in memory is fast enough most often it can have
+ some hiccups with 2 letter queries.
+- Finish server
+- Alpine package
+
+
+[^1]: https://sqlite.org/fts5.html
+[^2]: https://www.sqlite.org/spellfix1.html
+[^3]: https://www1.dict.cc/translation_file_request.php
+[4]: It may take some time depending the size of the dictionary you selected
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..b82608c
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+v0.1.0
diff --git a/cmd/dict/main.go b/cmd/dict/main.go
index 5bd6096..9dc98cf 100644
--- a/cmd/dict/main.go
+++ b/cmd/dict/main.go
@@ -1,16 +1,21 @@
package main
import (
+ "fmt"
"log/slog"
"os"
+ "path/filepath"
"github.com/urfave/cli/v2"
"git.gabrielgio.me/dict/cmd/importer"
"git.gabrielgio.me/dict/cmd/server"
"git.gabrielgio.me/dict/cmd/ui"
+ "git.gabrielgio.me/dict/db"
)
+var Version = "local"
+
func main() {
app := &cli.App{
Name: "dict",
@@ -19,6 +24,16 @@ func main() {
importer.ImportCommand,
ui.UICommand,
server.ServeCommand,
+ {
+ Name: "version",
+ Usage: "print current version",
+ Flags: []cli.Flag{},
+ Action: func(cCtx *cli.Context) error {
+ fmt.Printf("%s - %s\n\n", filepath.Base(os.Args[0]), Version)
+ fmt.Printf("Spellfix locaton: %s.so", db.LibPath)
+ return nil
+ },
+ },
},
}
diff --git a/db/db.go b/db/db.go
index 61f3bb5..c3699d7 100644
--- a/db/db.go
+++ b/db/db.go
@@ -9,6 +9,8 @@ import (
"github.com/mattn/go-sqlite3"
)
+var LibPath = "ext/libsqlite3ext"
+
type (
DB struct {
db *sql.DB
@@ -24,7 +26,7 @@ type (
func Open(filename string) (*DB, error) {
sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
- return conn.LoadExtension("ext/libsqlite3ext", "sqlite3_spellfix_init")
+ return conn.LoadExtension(LibPath, "sqlite3_spellfix_init")
},
})