feat: add health check and update README.md
This commit is contained in:
parent
c6ad825dac
commit
b2851cffd8
22
README.md
22
README.md
@ -28,36 +28,44 @@
|
|||||||
> 见 wiki
|
> 见 wiki
|
||||||
|
|
||||||
- 大部分功能可以自定义:
|
- 大部分功能可以自定义:
|
||||||
|
|
||||||
- 高亮
|
- 高亮
|
||||||
- 悬浮大小
|
- 悬浮大小
|
||||||
- 排版顺序
|
- 排版顺序
|
||||||
- 弹窗大小
|
- 弹窗大小
|
||||||
- `舒服窗口动画`
|
- `舒服窗口动画`
|
||||||
- etc (更多可以查看[配置](#配置))
|
- etc (更多可以查看[配置](#配置))
|
||||||
|
|
||||||
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
|
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
|
||||||
|
|
||||||
- 支持显示:
|
- 支持显示:
|
||||||
|
|
||||||
- 柯林斯星级
|
- 柯林斯星级
|
||||||
- 牛津 3000 词汇
|
- 牛津 3000 词汇
|
||||||
- 中文翻译
|
- 中文翻译
|
||||||
- 英文翻译 (不是英译中, 而是用英文解释)
|
- 英文翻译 (不是英译中, 而是用英文解释)
|
||||||
- 词根
|
- 词根
|
||||||
- etc
|
- etc
|
||||||
|
|
||||||
- 舒服的排版和`动画`
|
- 舒服的排版和`动画`
|
||||||
|
|
||||||
- 支持 `normal`和 `visual`模式
|
- 支持 `normal`和 `visual`模式
|
||||||
|
|
||||||
> <font color='#FF9900'>不支持 visual-block mode</font>
|
> <font color='#FF9900'>不支持 visual-block mode</font>
|
||||||
|
|
||||||
- 本地词库单词量: `430w`
|
- 本地词库单词量: `430w`
|
||||||
|
|
||||||
## 屏幕截图
|
## 屏幕截图
|
||||||
|
|
||||||
### 演示
|
### 演示
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4
|
|
||||||
|
|
||||||
> 视频演示的在线查询, 查询速度取决于你的网络状况
|
> 视频演示的在线查询, 查询速度取决于你的网络状况
|
||||||
> 可以打开音量查看自动读音
|
> 可以打开音量查看自动读音
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/107862700/215941500-3293c571-20a1-44e2-b202-77079f158ce9.mp4
|
https://user-images.githubusercontent.com/107862700/215941500-3293c571-20a1-44e2-b202-77079f158ce9.mp4
|
||||||
|
|
||||||
|
https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4
|
||||||
|
|
||||||
### 主题
|
### 主题
|
||||||
|
|
||||||
> 如果你有更美观或者更适合的配色, 欢迎提 PR
|
> 如果你有更美观或者更适合的配色, 欢迎提 PR
|
||||||
@ -145,10 +153,14 @@ use {
|
|||||||
|
|
||||||
<font color="#FF9900">**注意事项**: </font>
|
<font color="#FF9900">**注意事项**: </font>
|
||||||
|
|
||||||
|
- **如果插件无法正常工作, 请运行**`:check Trans`, 查看插件是否安装正确并且处于正常工作环境
|
||||||
|
|
||||||
- `install.sh`
|
- `install.sh`
|
||||||
|
|
||||||
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在 wget
|
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在 wget
|
||||||
|
|
||||||
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
|
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
|
||||||
|
|
||||||
- 目前仅在 `Ubuntu22.04`的环境下测试通过
|
- 目前仅在 `Ubuntu22.04`的环境下测试通过
|
||||||
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
|
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
|
||||||
> 如果上述条件满足, 仍出现问题, 欢迎在 issue 里向我反馈,我会及时尝试解决
|
> 如果上述条件满足, 仍出现问题, 欢迎在 issue 里向我反馈,我会及时尝试解决
|
||||||
@ -156,17 +168,16 @@ use {
|
|||||||
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
|
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
|
||||||
|
|
||||||
> 词库文件压缩包大小为: **281M**
|
> 词库文件压缩包大小为: **281M**
|
||||||
> 解压缩后的大小大概为: 1.2G
|
> 解压缩后的大小大概为: **1.2G**
|
||||||
|
|
||||||
- 安装后如果不能正常运行, 请尝试检查一下问题:
|
- 安装后如果不能正常运行, 请尝试检查一下问题:
|
||||||
|
|
||||||
- 本机是否已经安装了 `sqlite3`
|
- 本机是否已经安装了 `sqlite3`
|
||||||
|
|
||||||
> Linux 下安装:
|
> Linux 下安装:
|
||||||
> `sudo pacman -S sqlite # Arch`
|
> `sudo pacman -S sqlite # Arch`
|
||||||
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
|
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
|
||||||
|
|
||||||
> 后续会增加 `healthcheck` 进行检查
|
|
||||||
|
|
||||||
- **`auto_play`** 使用步骤:
|
- **`auto_play`** 使用步骤:
|
||||||
|
|
||||||
> linux 只需要安装`festival`
|
> linux 只需要安装`festival`
|
||||||
@ -176,6 +187,7 @@ use {
|
|||||||
|
|
||||||
> mac 系统使用`say` (感谢[@happysmile12321](https://github.com/happysmile12321) )
|
> mac 系统使用`say` (感谢[@happysmile12321](https://github.com/happysmile12321) )
|
||||||
|
|
||||||
|
|
||||||
> 其他操作系统
|
> 其他操作系统
|
||||||
- 需要确保安装了`nodejs`
|
- 需要确保安装了`nodejs`
|
||||||
- 进入插件的`tts`目录运行`npm install`
|
- 进入插件的`tts`目录运行`npm install`
|
||||||
|
63
lua/Trans/health.lua
Normal file
63
lua/Trans/health.lua
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.check = function()
|
||||||
|
local health = vim.health
|
||||||
|
local ok = health.report_ok
|
||||||
|
local warn = health.report_warn
|
||||||
|
local error = health.report_error
|
||||||
|
|
||||||
|
|
||||||
|
local has = vim.fn.has
|
||||||
|
local executable = vim.fn.executable
|
||||||
|
|
||||||
|
-- INFO :Check neovim version
|
||||||
|
if has('nvim-0.9') == 1 then
|
||||||
|
ok [[
|
||||||
|
[PASS]: you have Trans.nvim with full features in neovim-nightly
|
||||||
|
]]
|
||||||
|
else
|
||||||
|
warn [[
|
||||||
|
[WARN]: Trans Title requires Neovim 0.9 or newer
|
||||||
|
See neovim-nightly: https://github.com/neovim/neovim/releases/tag/nightly
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- INFO :Check Sqlite
|
||||||
|
local has_sqlite = pcall(require, 'sqlite')
|
||||||
|
if has_sqlite then
|
||||||
|
ok [[
|
||||||
|
[PASS]: Dependency sqlite.lua is installed
|
||||||
|
]]
|
||||||
|
else
|
||||||
|
error [[
|
||||||
|
[ERROR]: Dependency sqlite.lua can't work correctly
|
||||||
|
Please Read the doc in github carefully
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
if executable('sqlite3') then
|
||||||
|
ok [[
|
||||||
|
[PASS]: Dependency sqlite3 found
|
||||||
|
]]
|
||||||
|
else
|
||||||
|
error [[
|
||||||
|
[ERROR]: Dependency sqlite3 not found
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- INFO :Check stardict
|
||||||
|
local db_path = vim.fn.expand(require('Trans').conf.db_path)
|
||||||
|
if vim.fn.filereadable(db_path) == 1 then
|
||||||
|
ok [[
|
||||||
|
[PASS]: Stardict database found
|
||||||
|
]]
|
||||||
|
else
|
||||||
|
error [[
|
||||||
|
[PASS]: Stardict database not found
|
||||||
|
Please check the doc in github
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
@ -135,16 +135,8 @@ M.conf = {
|
|||||||
-- appPasswd = '',
|
-- appPasswd = '',
|
||||||
-- },
|
-- },
|
||||||
},
|
},
|
||||||
-- TODO :
|
|
||||||
-- register word
|
|
||||||
-- history = {
|
|
||||||
-- -- TOOD
|
|
||||||
-- }
|
|
||||||
|
|
||||||
-- TODO :add online translate engine
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local times = 0
|
|
||||||
M.setup = function(opts)
|
M.setup = function(opts)
|
||||||
if opts then
|
if opts then
|
||||||
M.conf = vim.tbl_deep_extend('force', M.conf, opts)
|
M.conf = vim.tbl_deep_extend('force', M.conf, opts)
|
||||||
@ -165,29 +157,13 @@ M.setup = function(opts)
|
|||||||
engines[i] = k
|
engines[i] = k
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
conf.engines = engines
|
conf.engines = engines
|
||||||
times = times + 1
|
|
||||||
if times == 1 then
|
|
||||||
---@format disable
|
|
||||||
local new_command = api.nvim_create_user_command
|
|
||||||
new_command('Translate' , function() M.translate() end, { desc = ' 单词翻译',})
|
|
||||||
new_command('TranslateInput' , function() M.translate('i') end, { desc = ' 搜索翻译',})
|
|
||||||
new_command('TransPlay' , function()
|
|
||||||
local word = M.get_word(api.nvim_get_mode().mode)
|
|
||||||
if word ~= '' and word:isEn() then
|
|
||||||
word:play()
|
|
||||||
end
|
|
||||||
end, { desc = ' 自动发音' })
|
|
||||||
|
|
||||||
|
|
||||||
local set_hl = api.nvim_set_hl
|
local set_hl = api.nvim_set_hl
|
||||||
local hls = require('Trans.ui.theme')[conf.theme]
|
local hls = require('Trans.ui.theme')[conf.theme]
|
||||||
for hl, opt in pairs(hls) do
|
for hl, opt in pairs(hls) do
|
||||||
set_hl(0, hl, opt)
|
set_hl(0, hl, opt)
|
||||||
end
|
end
|
||||||
---@format enable
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_select()
|
local function get_select()
|
||||||
@ -209,7 +185,6 @@ local function get_select()
|
|||||||
|
|
||||||
if s_row == e_row then
|
if s_row == e_row then
|
||||||
return line:sub(s_col, e_col)
|
return line:sub(s_col, e_col)
|
||||||
|
|
||||||
else
|
else
|
||||||
local lines = fn.getline(s_row, e_row)
|
local lines = fn.getline(s_row, e_row)
|
||||||
local i = #lines
|
local i = #lines
|
||||||
@ -223,11 +198,9 @@ M.get_word = function(mode)
|
|||||||
local word
|
local word
|
||||||
if mode == 'n' then
|
if mode == 'n' then
|
||||||
word = fn.expand('<cword>')
|
word = fn.expand('<cword>')
|
||||||
|
|
||||||
elseif mode == 'v' then
|
elseif mode == 'v' then
|
||||||
api.nvim_input('<ESC>')
|
api.nvim_input('<ESC>')
|
||||||
word = get_select()
|
word = get_select()
|
||||||
|
|
||||||
elseif mode == 'i' then
|
elseif mode == 'i' then
|
||||||
-- TODO Use Telescope with fuzzy finder
|
-- TODO Use Telescope with fuzzy finder
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
|
12
plugin/Trans.lua
Normal file
12
plugin/Trans.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
local M = require("Trans")
|
||||||
|
local api = vim.api
|
||||||
|
local command = api.nvim_create_user_command
|
||||||
|
|
||||||
|
command('Translate', function() M.translate() end, { desc = ' 单词翻译', })
|
||||||
|
command('TranslateInput', function() M.translate('i') end, { desc = ' 搜索翻译', })
|
||||||
|
command('TransPlay', function()
|
||||||
|
local word = M.get_word(api.nvim_get_mode().mode)
|
||||||
|
if word ~= '' and word:isEn() then
|
||||||
|
word:play()
|
||||||
|
end
|
||||||
|
end, { desc = ' 自动发音' })
|
Loading…
x
Reference in New Issue
Block a user