feat: add health check and update README.md
This commit is contained in:
parent
c6ad825dac
commit
b2851cffd8
248
README.md
248
README.md
@ -2,83 +2,91 @@
|
|||||||
|
|
||||||
<!--toc:start-->
|
<!--toc:start-->
|
||||||
|
|
||||||
- [Trans.nvim](#transnvim)
|
- [Trans.nvim](#transnvim)
|
||||||
- [特点](#特点)
|
- [特点](#特点)
|
||||||
- [屏幕截图](#屏幕截图)
|
- [屏幕截图](#屏幕截图)
|
||||||
- [演示](#演示)
|
- [演示](#演示)
|
||||||
- [主题](#主题)
|
- [主题](#主题)
|
||||||
- [安装](#安装)
|
- [安装](#安装)
|
||||||
- [配置](#配置)
|
- [配置](#配置)
|
||||||
- [快捷键绑定](#快捷键绑定)
|
- [快捷键绑定](#快捷键绑定)
|
||||||
- [高亮组](#高亮组)
|
- [高亮组](#高亮组)
|
||||||
- [声明](#声明)
|
- [声明](#声明)
|
||||||
- [感谢](#感谢)
|
- [感谢](#感谢)
|
||||||
- [贡献](#贡献)
|
- [贡献](#贡献)
|
||||||
- [待办 (画大饼)](#待办-画大饼)
|
- [待办 (画大饼)](#待办-画大饼)
|
||||||
<!--toc:end-->
|
<!--toc:end-->
|
||||||
|
|
||||||
## 特点
|
## 特点
|
||||||
|
|
||||||
- 使用纯 lua 编写, 速度极快
|
- 使用纯 lua 编写, 速度极快
|
||||||
|
|
||||||
> `Lazy.nvim`的记录: <font color="#0099FF">`➜ Trans.nvim 0.82ms`</font>
|
> `Lazy.nvim`的记录: <font color="#0099FF">`➜ Trans.nvim 0.82ms`</font>
|
||||||
|
|
||||||
- **可以定义快捷键读英文单词**
|
- **可以定义快捷键读英文单词**
|
||||||
|
|
||||||
> 见 wiki
|
> 见 wiki
|
||||||
|
|
||||||
- 大部分功能可以自定义:
|
- 大部分功能可以自定义:
|
||||||
- 高亮
|
|
||||||
- 悬浮大小
|
- 高亮
|
||||||
- 排版顺序
|
- 悬浮大小
|
||||||
- 弹窗大小
|
- 排版顺序
|
||||||
- `舒服窗口动画`
|
- 弹窗大小
|
||||||
- etc (更多可以查看[配置](#配置))
|
- `舒服窗口动画`
|
||||||
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
|
- etc (更多可以查看[配置](#配置))
|
||||||
- 支持显示:
|
|
||||||
- 柯林斯星级
|
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
|
||||||
- 牛津 3000 词汇
|
|
||||||
- 中文翻译
|
- 支持显示:
|
||||||
- 英文翻译 (不是英译中, 而是用英文解释)
|
|
||||||
- 词根
|
- 柯林斯星级
|
||||||
- etc
|
- 牛津 3000 词汇
|
||||||
- 舒服的排版和`动画`
|
- 中文翻译
|
||||||
- 支持 `normal`和 `visual`模式
|
- 英文翻译 (不是英译中, 而是用英文解释)
|
||||||
> <font color='#FF9900'>不支持 visual-block mode</font>
|
- 词根
|
||||||
- 本地词库单词量: `430w`
|
- etc
|
||||||
|
|
||||||
|
- 舒服的排版和`动画`
|
||||||
|
|
||||||
|
- 支持 `normal`和 `visual`模式
|
||||||
|
|
||||||
|
> <font color='#FF9900'>不支持 visual-block mode</font>
|
||||||
|
|
||||||
|
- 本地词库单词量: `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
|
||||||
> 主题配色在: `lua/Trans/theme.lua`文件中,你只需要添加你主题的表就可以了
|
> 主题配色在: `lua/Trans/theme.lua`文件中,你只需要添加你主题的表就可以了
|
||||||
|
|
||||||
- `default`
|
- `default`
|
||||||

|

|
||||||
|
|
||||||
- `dracula`
|
- `dracula`
|
||||||

|

|
||||||
|
|
||||||
- `tokyonight`
|
- `tokyonight`
|
||||||

|

|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
_安装之前, 首先需要明确本插件的依赖:_
|
_安装之前, 首先需要明确本插件的依赖:_
|
||||||
|
|
||||||
- [ECDICT](https://github.com/skywind3000/ECDICT): 插件所用的离线单词数据库
|
- [ECDICT](https://github.com/skywind3000/ECDICT): 插件所用的离线单词数据库
|
||||||
- sqlite.lua: 操作数据库所用的库
|
- sqlite.lua: 操作数据库所用的库
|
||||||
- sqlite3: 数据库
|
- sqlite3: 数据库
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Packer.nvim</summary>
|
<summary>Packer.nvim</summary>
|
||||||
@ -145,43 +153,47 @@ use {
|
|||||||
|
|
||||||
<font color="#FF9900">**注意事项**: </font>
|
<font color="#FF9900">**注意事项**: </font>
|
||||||
|
|
||||||
- `install.sh`
|
- **如果插件无法正常工作, 请运行**`:check Trans`, 查看插件是否安装正确并且处于正常工作环境
|
||||||
|
|
||||||
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在 wget
|
- `install.sh`
|
||||||
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
|
|
||||||
- 目前仅在 `Ubuntu22.04`的环境下测试通过
|
|
||||||
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
|
|
||||||
> 如果上述条件满足, 仍出现问题, 欢迎在 issue 里向我反馈,我会及时尝试解决
|
|
||||||
|
|
||||||
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
|
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在 wget
|
||||||
|
|
||||||
> 词库文件压缩包大小为: **281M**
|
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
|
||||||
> 解压缩后的大小大概为: 1.2G
|
|
||||||
|
|
||||||
- 安装后如果不能正常运行, 请尝试检查一下问题:
|
- 目前仅在 `Ubuntu22.04`的环境下测试通过
|
||||||
|
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
|
||||||
|
> 如果上述条件满足, 仍出现问题, 欢迎在 issue 里向我反馈,我会及时尝试解决
|
||||||
|
|
||||||
- 本机是否已经安装了 `sqlite3`
|
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
|
||||||
> Linux 下安装:
|
|
||||||
> `sudo pacman -S sqlite # Arch`
|
|
||||||
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
|
|
||||||
|
|
||||||
> 后续会增加 `healthcheck` 进行检查
|
> 词库文件压缩包大小为: **281M**
|
||||||
|
> 解压缩后的大小大概为: **1.2G**
|
||||||
|
|
||||||
- **`auto_play`** 使用步骤:
|
- 安装后如果不能正常运行, 请尝试检查一下问题:
|
||||||
|
|
||||||
> linux 只需要安装`festival`
|
- 本机是否已经安装了 `sqlite3`
|
||||||
> sudo apt-get install festival festvox-kallpc16k
|
|
||||||
> **_如果你想要设置音色,发音可以访问:_** [Festival 官方](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html)
|
|
||||||
> 可以选择英音、美音、男声、女声
|
|
||||||
|
|
||||||
> mac 系统使用`say` (感谢[@happysmile12321](https://github.com/happysmile12321) )
|
> Linux 下安装:
|
||||||
|
> `sudo pacman -S sqlite # Arch`
|
||||||
|
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
|
||||||
|
|
||||||
> 其他操作系统
|
- **`auto_play`** 使用步骤:
|
||||||
- 需要确保安装了`nodejs`
|
|
||||||
- 进入插件的`tts`目录运行`npm install`
|
|
||||||
> 如果`install.sh`运行正常则自动安装,如果安装失败,请尝试手动安装
|
|
||||||
|
|
||||||
- `title`的配置,只对`neovim 0.9`版本有效
|
> linux 只需要安装`festival`
|
||||||
|
> sudo apt-get install festival festvox-kallpc16k
|
||||||
|
> **_如果你想要设置音色,发音可以访问:_** [Festival 官方](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html)
|
||||||
|
> 可以选择英音、美音、男声、女声
|
||||||
|
|
||||||
|
> mac 系统使用`say` (感谢[@happysmile12321](https://github.com/happysmile12321) )
|
||||||
|
|
||||||
|
|
||||||
|
> 其他操作系统
|
||||||
|
- 需要确保安装了`nodejs`
|
||||||
|
- 进入插件的`tts`目录运行`npm install`
|
||||||
|
> 如果`install.sh`运行正常则自动安装,如果安装失败,请尝试手动安装
|
||||||
|
|
||||||
|
- `title`的配置,只对`neovim 0.9`版本有效
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Festival配置(仅针对linux用户)</summary>
|
<summary>Festival配置(仅针对linux用户)</summary>
|
||||||
@ -189,45 +201,45 @@ use {
|
|||||||
- 全局配置: `/usr/share/festival/siteinit.scm`
|
- 全局配置: `/usr/share/festival/siteinit.scm`
|
||||||
- 用户配置: `~/.festivalrc`
|
- 用户配置: `~/.festivalrc`
|
||||||
|
|
||||||
- 更改声音
|
- 更改声音
|
||||||
|
|
||||||
- 在 festival 的 voices 文件内建立自己的文件夹
|
- 在 festival 的 voices 文件内建立自己的文件夹
|
||||||
|
|
||||||
> 一般其默认配置目录在`/usr/share/festival/voices`
|
> 一般其默认配置目录在`/usr/share/festival/voices`
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
> `sudo mkdir /usr/share/festival/voices/my_voices`
|
> `sudo mkdir /usr/share/festival/voices/my_voices`
|
||||||
|
|
||||||
- 下载想要的 voices 文件并解压
|
- 下载想要的 voices 文件并解压
|
||||||
|
|
||||||
|
> 可能需要
|
||||||
|
|
||||||
|
- 试听[在这里](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html))
|
||||||
|
- 下载[在这里](http://festvox.org/packed/festival/2.5/voices/))
|
||||||
|
> 假设下载的文件在`Downloads`文件夹, 下载的文件为:`festvox_cmu_us_aew_cg.tar.gz`
|
||||||
|
|
||||||
|
示例:
|
||||||
|
|
||||||
|
> `cd ~/Downloads && tar -xf festvox_cmu_us_aew_cg.tar.gz`
|
||||||
|
|
||||||
|
- 将音频文件拷贝到 festival 文件夹
|
||||||
|
示例:
|
||||||
|
|
||||||
|
> `sudo cp -r festival/lib/voices/us/cmu_us_aew_cg/ /usr/share/festival/voices/my_voices/`
|
||||||
|
|
||||||
|
- 在配置文件中设置默认的声音
|
||||||
|
示例:
|
||||||
|
|
||||||
|
> 加入`(set! voice_default voice_cmu_indic_hin_ab_cg)`到配置文件
|
||||||
|
|
||||||
|
- 安装完成
|
||||||
|
|
||||||
|
- 相关说明网站
|
||||||
> 可能需要
|
> 可能需要
|
||||||
|
- [wiki](https://archlinux.org/packages/community/any/festival-us/) 查看更多详细配置
|
||||||
- 试听[在这里](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html))
|
- [官方网站](http://festvox.org/dbs/index.html)
|
||||||
- 下载[在这里](http://festvox.org/packed/festival/2.5/voices/))
|
- [用户手册](http://www.festvox.org/docs/manual-2.4.0/festival_toc.html)
|
||||||
> 假设下载的文件在`Downloads`文件夹, 下载的文件为:`festvox_cmu_us_aew_cg.tar.gz`
|
|
||||||
|
|
||||||
示例:
|
|
||||||
|
|
||||||
> `cd ~/Downloads && tar -xf festvox_cmu_us_aew_cg.tar.gz`
|
|
||||||
|
|
||||||
- 将音频文件拷贝到 festival 文件夹
|
|
||||||
示例:
|
|
||||||
|
|
||||||
> `sudo cp -r festival/lib/voices/us/cmu_us_aew_cg/ /usr/share/festival/voices/my_voices/`
|
|
||||||
|
|
||||||
- 在配置文件中设置默认的声音
|
|
||||||
示例:
|
|
||||||
|
|
||||||
> 加入`(set! voice_default voice_cmu_indic_hin_ab_cg)`到配置文件
|
|
||||||
|
|
||||||
- 安装完成
|
|
||||||
|
|
||||||
- 相关说明网站
|
|
||||||
> 可能需要
|
|
||||||
- [wiki](https://archlinux.org/packages/community/any/festival-us/) 查看更多详细配置
|
|
||||||
- [官方网站](http://festvox.org/dbs/index.html)
|
|
||||||
- [用户手册](http://www.festvox.org/docs/manual-2.4.0/festival_toc.html)
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -408,13 +420,13 @@ vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
|
|||||||
|
|
||||||
## 声明
|
## 声明
|
||||||
|
|
||||||
- 本插件词典基于[ECDICT](https://github.com/skywind3000/ECDICT)
|
- 本插件词典基于[ECDICT](https://github.com/skywind3000/ECDICT)
|
||||||
|
|
||||||
## 感谢
|
## 感谢
|
||||||
|
|
||||||
- [ECDICT](https://github.com/skywind3000/ECDICT) 本地词典的提供
|
- [ECDICT](https://github.com/skywind3000/ECDICT) 本地词典的提供
|
||||||
- [sqlite.lua](https://github.com/kharji/sqlite.lua) 数据库访问
|
- [sqlite.lua](https://github.com/kharji/sqlite.lua) 数据库访问
|
||||||
- [T.vim](https://github.com/sicong-li/T.vim) 灵感来源
|
- [T.vim](https://github.com/sicong-li/T.vim) 灵感来源
|
||||||
|
|
||||||
## 贡献
|
## 贡献
|
||||||
|
|
||||||
@ -423,11 +435,11 @@ vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
|
|||||||
|
|
||||||
## 待办 (画大饼)
|
## 待办 (画大饼)
|
||||||
|
|
||||||
- [x] 多风格样式查询
|
- [x] 多风格样式查询
|
||||||
- [x] 重新录制屏幕截图示例
|
- [x] 重新录制屏幕截图示例
|
||||||
- [x] 快捷键定义
|
- [x] 快捷键定义
|
||||||
- [x] 自动读音
|
- [x] 自动读音
|
||||||
- [ ] 变量命名的支持
|
- [ ] 变量命名的支持
|
||||||
- [ ] 历史查询结果保存
|
- [ ] 历史查询结果保存
|
||||||
- [ ] 在线多引擎异步查询
|
- [ ] 在线多引擎异步查询
|
||||||
- [ ] `句子翻译` | `中翻英` 的支持
|
- [ ] `句子翻译` | `中翻英` 的支持
|
||||||
|
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
|
@ -6,10 +6,10 @@ if fn.executable('sqlite3') ~= 1 then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local win_title = fn.has('nvim-0.9') == 1 and {
|
local win_title = fn.has('nvim-0.9') == 1 and {
|
||||||
{ '', 'TransTitleRound' },
|
{ '', 'TransTitleRound' },
|
||||||
{ ' Trans', 'TransTitle' },
|
{ ' Trans', 'TransTitle' },
|
||||||
{ '', 'TransTitleRound' },
|
{ '', 'TransTitleRound' },
|
||||||
} or nil
|
} or nil
|
||||||
|
|
||||||
-- local title = {
|
-- local title = {
|
||||||
-- "████████╗██████╗ █████╗ ███╗ ██╗███████╗",
|
-- "████████╗██████╗ █████╗ ███╗ ██╗███████╗",
|
||||||
@ -32,16 +32,16 @@ string.isEn = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
string.play = fn.has('linux') == 1 and function(self)
|
string.play = fn.has('linux') == 1 and function(self)
|
||||||
local cmd = ([[echo "%s" | festival --tts]]):format(self)
|
local cmd = ([[echo "%s" | festival --tts]]):format(self)
|
||||||
fn.jobstart(cmd)
|
fn.jobstart(cmd)
|
||||||
end or fn.has('mac') == 1 and function (self)
|
end or fn.has('mac') == 1 and function(self)
|
||||||
local cmd = ([[say "%s"]]):format(self)
|
local cmd = ([[say "%s"]]):format(self)
|
||||||
fn.jobstart(cmd)
|
fn.jobstart(cmd)
|
||||||
end or function(self)
|
end or function(self)
|
||||||
local seperator = fn.has('unix') and '/' or '\\'
|
local seperator = fn.has('unix') and '/' or '\\'
|
||||||
local file = debug.getinfo(1, "S").source:sub(2):match('(.*)lua') .. seperator .. 'tts' .. seperator .. 'say.js'
|
local file = debug.getinfo(1, "S").source:sub(2):match('(.*)lua') .. seperator .. 'tts' .. seperator .. 'say.js'
|
||||||
fn.jobstart('node ' .. file .. ' ' .. self)
|
fn.jobstart('node ' .. file .. ' ' .. self)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.conf = {
|
M.conf = {
|
||||||
view = {
|
view = {
|
||||||
@ -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,28 +157,12 @@ 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
|
|
||||||
---@format enable
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -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