diff --git a/.gitignore b/.gitignore index 70eae03..89f94ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ lua/Trans/util/ lua/Trans/test/ note/ go/ +demo.mp4 +screenshot.gif diff --git a/README.md b/README.md index 1b5f88c..e8c6e55 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ - 悬浮大小 - 排版顺序 - 弹窗大小 + - `舒服窗口动画` - etc (更多可以查看[配置](#配置)) - **完全离线** 的单词翻译体验 (可能后面会支持在线翻译) - 支持显示: @@ -37,7 +38,7 @@ - 本地词库单词量: `430w` ## 屏幕截图 -![ScreenShot](./screenshot.gif) +https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4 ## 安装 @@ -46,6 +47,7 @@ - sqlite.lua: 操作数据库所用的库 - sqlite3: 数据库 + 由于目前本人只使用 `Packer.nvim` 作为包管理插件, 所以这里以Packer为例: **考虑将以下代码复制到的Packer Startup中:** ```lua @@ -54,9 +56,12 @@ use { run = 'bash ./install.sh', requires = 'kharji/sqlite.lua', -- 如果你不需要任何配置的话, 可以直接按照下面的方式启动 - config = require'Trans'.setup + config = function () + require'Trans'.setup{ + -- your configuration here + } + end } - ``` **如果你想要使用Packer的惰性加载,这里有一个例子** @@ -103,23 +108,50 @@ use { ```lua require'Trans'.setup { view = { - input = 'float', + i = 'float', n = 'hover', v = 'hover', }, - window = { + hover = { + width = 36, + height = 26, border = 'rounded', - animation = true, - hover = { - width = 36, - height = 26, + title = { + { '', 'TransTitleRound' }, + { ' Trans', 'TransTitle' }, + { '', 'TransTitleRound' }, }, - float = { - width = 0.8, - height = 0.8, + keymap = { + -- TODO : + pageup = '[[', + pagedown = ']]', + pin = '_', -- 将窗口固定在右上角, 参考demo + close = '+', }, + animation = { + open = 'slid', -- 可选的样式: slid , fold + close = 'slid', + interval = 12, -- 动画的帧间隔 + } + }, + float = { + width = 0.8, + height = 0.8, + border = 'rounded', + title = { + { '', 'TransTitleRound' }, + { ' Trans', 'TransTitle' }, + { '', 'TransTitleRound' }, + }, + keymap = { + quit = 'q', + }, + animation = { + open = 'fold', + close = 'fold', + interval = 10, + } }, - order = { -- offline = { 'title', @@ -134,29 +166,22 @@ require'Trans'.setup { -- }, }, icon = { - title = ' ', --  star = '', - -- notfound = ' ', - -- yes = ' ', - -- no = ' ' - -- star = '⭐', notfound = '❔', yes = '✔️', no = '❌' + -- star = '⭐', + -- notfound = '', + -- yes = '', + -- no = '' }, db_path = '$HOME/.vim/dict/ultimate.db', + -- TODO : -- engine = { -- -- TODO -- 'offline', -- } - keymap = { - -- TODO : More action support - hover = { - pageup = '[[', - pagedown = ']]', - }, - }, -- history = { -- -- TOOD -- } diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index 389b50f..f394113 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -6,7 +6,6 @@ M.conf = { n = 'hover', v = 'hover', }, - -- animation = true, hover = { width = 36, height = 26, @@ -24,6 +23,8 @@ M.conf = { close = '+', }, animation = { + -- open = 'fold', + -- close = 'fold', open = 'slid', close = 'slid', interval = 12, @@ -42,9 +43,9 @@ M.conf = { quit = 'q', }, animation = { - open = 'slid', - close = 'slid', - interval = 8, + open = 'fold', + close = 'fold', + interval = 10, } }, order = { @@ -54,8 +55,6 @@ M.conf = { 'pos', 'exchange', 'translation', - -- NOTE :如果你想限制某个组件的行数,可以设置max_size - -- { 'Definition', max_size = 4 }, 'definition', -- }, -- online = { diff --git a/lua/Trans/view/float.lua b/lua/Trans/view/float.lua index b16f929..e43fc4a 100644 --- a/lua/Trans/view/float.lua +++ b/lua/Trans/view/float.lua @@ -1,28 +1,44 @@ --- local m_window --- local m_result --- --- --- return function(word) --- -- TODO :online query --- m_result = require('Trans.query.offline')(word) --- m_window = require('Trans.window') --- local float = require('Trans').conf.float --- --- local opt = { --- relative = 'editor', --- width = float.width, --- height = float.height, --- border = float.border, --- title = float.title, --- row = math.floor((vim.o.lines - float.height) / 2), --- col = math.floor((vim.o.columns - float.width) / 2), --- } --- --- -- 创建窗口 --- m_window.init(true, opt) --- m_window.center('https:github.com/JuanZoran/Trans.nvim', '@text.uri') -- only show color with treesiter --- m_window.draw() --- m_window.map('q', function() --- m_window.try_close(float.animation) --- end) --- end +local m_window +local m_result + +local function set_title() + local title = m_window.title + local github = 'https://github.com/JuanZoran/Trans.nvim' + + -- TODO :config this + title:center_line(github, '@text.uri') +end + +local action = { + quit = function () + m_window:try_close() + end, +} + + +return function(word) + -- TODO :online query + local float = require('Trans').conf.float + m_result = require('Trans.query.offline')(word) + + local opt = { + relative = 'editor', + width = float.width, + height = float.height, + border = float.border, + title = float.title, + row = math.floor((vim.o.lines - float.height) / 2), + col = math.floor((vim.o.columns - float.width) / 2), + } + m_window = require('Trans.window')(true, opt) + m_window.animation = float.animation + + set_title() + m_window:draw() + m_window:open() + m_window:bufset('bufhidden', 'wipe') + + for act, key in pairs(float.keymap) do + m_window:map(key, action[act]) + end +end diff --git a/lua/Trans/window.lua b/lua/Trans/window.lua index c081d58..2c81bc7 100644 --- a/lua/Trans/window.lua +++ b/lua/Trans/window.lua @@ -278,6 +278,7 @@ return function(entry, option) win:set('winhl', 'Normal:TransWin,FloatBorder:TransBorder') win:bufset('filetype', 'Trans') + win:bufset('buftype', 'nofile') ---@diagnostic disable-next-line: return-type-mismatch return win diff --git a/screenshot.gif b/screenshot.gif deleted file mode 100644 index 78465f8..0000000 Binary files a/screenshot.gif and /dev/null differ