ondict

command module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

README

Introduction

Yet another simple dictionary application. Support multiple sources, including Longman online dictionary, and user-loaded MDX/MDD dictionary files.

Gif

Other choices

There are some similar products. They are all mature products, but may not suit me(or you) in some cases. Compared to these, this application is not yet so well polished, but it has its own advantages.

  • It's a CLI application, conforming to the UNIX stdout convention. So you can further process the output, or embed it into any UNIX-like CLI tools.
  • The output can be plain text(such as Markdown format), so feel free to render it with any renderer. You can also embed it into your extensible editor. I provide neovim integration out of the box.
  • The output can also be internally rendered as HTML, and your can just use it to build a server, which you can access anywhere by your browser, without having to install any other apps.
  • Easy to cross platform. The core is written in Go.
  • It's free and open source, just fork/PR/issue it if you like!

Prerequisites

  • Go version >=1.16, and add $GOBIN in your $PATH
  • Neovim version >= 0.9.1 [recommended, because I developed it on this version, but previous versions may also use it, only some "lsp" utils (not lsp feature itself) is required. So it can also be ported to Vim, but I am not quite familiar with vim's popup feature yet]

Installation

go install github.com/ChaosNyaruko/ondict@latest

Usage

CLI

Help
ondict 
ondict -h
Examples
One-shot query
ondict -q <word>
One-shot query, but from remote server
ondict -q <word> -remote auto 
A "repl" querier
ondict -i

input .help for commands that can be used.

Work as a server

This app can also serve as a HTTP server, allowing remote fetch and query, with cache and acceleration.

ondict -server -listen=localhost:1345 -engine=mdx

Launch a http request

curl "http://localhost:1345/?query=apple&engine=mdx&format=x"

If you are visiting the URL with a web browser, setting format to "html" is recommended. The browser will automatically render a more beautiful page than it is in the "CLI" interface.

You can also deploy it on your server, as an upstream of Nginx/, or just exposing it with a suitable ip/port.

You can run make serve locally for an easy example. My front-end skill is poor, so the page is ugly and rough, don't hate it :(.

There are still a lot of TODOs, free free to give me PRs and contribute to the immature project, thanks in advance.

Working with Neovim

  1. Install the plugin with a plugin manager or manually.
  2. Use :lua require("ondict").query() to query <cword>.
  3. Define a mapping for yourself to call it easier. NOTE: in visual mode, use "<cmd>lua require("ondict").query()<cr>" instead. It will capture the "SELECTED" word. Otherwise, the "mode" will be changed and only "<cword>" can be queried.

Install the "ondict" binary automatically with lazy.

{ 
    "ChaosNyaruko/ondict",
    event = "VeryLazy",
    build = function(plugin)
        require("ondict").install(plugin.dir)
    end
}

Manually

cd ~/.local/share/nvim/site/pack/packer/start/
git clone https://github.com/ChaosNyaruko/ondict.git
cd ondict
go install .
Mapping examples
nnoremap <leader>d <cmd>lua require("ondict").query()<cr>
vnoremap <leader>d <cmd>lua require("ondict").query()<cr>
vim.keymap.set("n", "<leader>d", require("ondict").query)
vim.keymap.set("v", "<leader>d", require("ondict").query)

Offline dictionary files

Put the decoded JSON files in $HOME/.config/ondict/dicts

Features

  • Online query support based on Longman online dictionary
  • Integrated with (n)vim, feel free to use it in whatever editor you are using!
  • Offline engine/mode is supported. The online engine may be more comprehensive and updated, but they are slow since an HTTP request is made for the first time.

LICENSE

LICENSE

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package decoder provides a way to decode MDX/MDD file in a native way, rather than an external python scripts.
Package decoder provides a way to decode MDX/MDD file in a native way, rather than an external python scripts.
Aho–Corasick algorithm Refer to https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm https://www.youtube.com/watch?v=O7_w001f58c https://www.youtube.com/watch?v=OFKxWFew_L0
Aho–Corasick algorithm Refer to https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm https://www.youtube.com/watch?v=O7_w001f58c https://www.youtube.com/watch?v=OFKxWFew_L0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL