refactor: implement waitting window animation
This commit is contained in:
parent
3c28af5314
commit
9d0aca954d
@ -1,5 +1,4 @@
|
||||
local Trans = require('Trans')
|
||||
local style = Trans.conf.style
|
||||
|
||||
local M = Trans.metatable('frontend.hover')
|
||||
|
||||
@ -25,13 +24,38 @@ end
|
||||
function M.clear_dead_instance()
|
||||
for i = #M.queue, 1, -1 do
|
||||
if not M.queue[i]:is_available() then
|
||||
--- FIXME :Del Buffer or ... ?
|
||||
table.remove(M.queue, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.new_window()
|
||||
---Init hover window
|
||||
---@param opts table @window options: width, height
|
||||
---@return unknown
|
||||
function M:init_window(opts)
|
||||
opts = opts or {}
|
||||
local win_opts = opts.win_opts or {}
|
||||
opts.win_opts = win_opts
|
||||
local m_opts = self.opts
|
||||
|
||||
|
||||
opts.buffer = self.buffer
|
||||
win_opts.col = 1
|
||||
win_opts.row = 1
|
||||
win_opts.relative = 'cursor'
|
||||
win_opts.title = m_opts.title
|
||||
if win_opts.title then
|
||||
win_opts.title_pos = 'center'
|
||||
end
|
||||
win_opts.width = win_opts.width or m_opts.width
|
||||
win_opts.height = win_opts.height or m_opts.height
|
||||
opts.animation = m_opts.animation
|
||||
|
||||
|
||||
|
||||
self.window = Trans.wrapper.window.new(opts)
|
||||
return self.window
|
||||
end
|
||||
|
||||
function M:wait(tbl, name, timeout)
|
||||
@ -44,12 +68,19 @@ function M:wait(tbl, name, timeout)
|
||||
return spinner[times % size + 1] .. ('.'):rep(times)
|
||||
end
|
||||
|
||||
self:init_window({
|
||||
win_opts = {
|
||||
height = 1,
|
||||
width = wid,
|
||||
}
|
||||
})
|
||||
|
||||
local interval = math.floor(timeout / wid)
|
||||
local pause = Trans.util.pause
|
||||
for i = 1, wid do
|
||||
if tbl[name] ~= nil then break end
|
||||
print(update_text(i))
|
||||
Trans.util.pause(interval)
|
||||
self.buffer[1] = update_text(i)
|
||||
pause(interval)
|
||||
end
|
||||
|
||||
-- TODO : End waitting animation
|
||||
|
@ -130,13 +130,6 @@ function buffer:addline(nodes, index)
|
||||
end
|
||||
end
|
||||
|
||||
function buffer:init()
|
||||
self.bufnr = api.nvim_create_buf(false, false)
|
||||
self:set('filetype', 'Trans')
|
||||
self:set('buftype', 'nofile')
|
||||
self.size = 0
|
||||
end
|
||||
|
||||
---@private
|
||||
buffer.__index = function(self, key)
|
||||
local res = buffer[key]
|
||||
@ -158,10 +151,16 @@ end
|
||||
---buffer constructor
|
||||
---@return buf
|
||||
function buffer.new()
|
||||
return setmetatable({
|
||||
local new_buf = setmetatable({
|
||||
bufnr = -1,
|
||||
size = 0,
|
||||
}, buffer)
|
||||
|
||||
|
||||
new_buf.bufnr = api.nvim_create_buf(false, false)
|
||||
new_buf:set('filetype', 'Trans')
|
||||
new_buf:set('buftype', 'nofile')
|
||||
return new_buf
|
||||
end
|
||||
|
||||
return buffer
|
||||
|
@ -113,7 +113,6 @@ function window:set_hl(name, opts)
|
||||
end
|
||||
|
||||
function window:open()
|
||||
assert(self.winid == nil, 'window already opened')
|
||||
local win_opts = self.win_opts
|
||||
local open_animation = self.animation.open
|
||||
if open_animation then
|
||||
|
Loading…
x
Reference in New Issue
Block a user