2021-03-14 19:18:18 +00:00
|
|
|
local opts = {}
|
|
|
|
local M = {}
|
2021-03-14 02:13:40 +00:00
|
|
|
|
2021-03-14 19:18:18 +00:00
|
|
|
local old_cur
|
|
|
|
|
|
|
|
function M.on_cursor_moved()
|
|
|
|
local cur = vim.api.nvim_win_get_cursor(0)
|
|
|
|
if old_cur then
|
|
|
|
jump = math.abs(cur[1]-old_cur[1])
|
|
|
|
if jump >= opts.min_jump then
|
|
|
|
M.show_specs()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
old_cur = cur
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.show_specs()
|
2021-03-14 02:13:40 +00:00
|
|
|
local bufh = vim.api.nvim_create_buf(false, true)
|
2021-03-14 22:21:26 +00:00
|
|
|
local win_id = vim.api.nvim_open_win(bufh, false, {
|
2021-03-14 02:13:40 +00:00
|
|
|
relative='win',
|
2021-03-15 00:31:22 +00:00
|
|
|
width = 1,
|
2021-03-14 02:13:40 +00:00
|
|
|
height = 1,
|
2021-03-15 00:31:22 +00:00
|
|
|
col = vim.fn.wincol()-1,
|
|
|
|
row = vim.fn.winline()-1,
|
2021-03-14 02:13:40 +00:00
|
|
|
style = 'minimal'
|
|
|
|
})
|
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
local cnt = 0
|
2021-03-14 02:13:40 +00:00
|
|
|
local timer = vim.loop.new_timer()
|
2021-03-14 19:18:18 +00:00
|
|
|
vim.loop.timer_start(timer, opts.popup.delay_ms, opts.popup.inc_ms, vim.schedule_wrap(function()
|
2021-03-14 02:13:40 +00:00
|
|
|
if vim.api.nvim_win_is_valid(win_id) then
|
2021-03-15 00:31:22 +00:00
|
|
|
local fade_done = opts.popup.fader(win_id, cnt)
|
|
|
|
local resize_done = opts.popup.resizer(win_id, cnt)
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
if fade_done and resize_done then
|
2021-03-14 02:13:40 +00:00
|
|
|
vim.loop.close(timer)
|
|
|
|
vim.api.nvim_win_close(win_id, true)
|
|
|
|
end
|
2021-03-15 00:31:22 +00:00
|
|
|
cnt = cnt+1
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
end))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Used as the default fader
|
2021-03-15 02:46:07 +00:00
|
|
|
--[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]--
|
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
function M.linear_fader(win_id, cnt)
|
|
|
|
if opts.popup.blend+cnt < 100 then
|
|
|
|
vim.api.nvim_win_set_option(win_id, "winblend", opts.popup.blend+cnt)
|
|
|
|
return false
|
|
|
|
else return true end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
|
|
|
--[[ ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ ]]--
|
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
function M.pulse_fader(win_id, cnt)
|
2021-03-15 02:46:07 +00:00
|
|
|
local bl = opts.popup.blend
|
|
|
|
if cnt < (100-bl)/2 then
|
|
|
|
vim.api.nvim_win_set_option(win_id, "winblend", bl+cnt)
|
|
|
|
return false
|
|
|
|
elseif cnt < 100-bl then
|
|
|
|
vim.api.nvim_win_set_option(win_id, "winblend", 100-cnt)
|
|
|
|
return false
|
|
|
|
else return true end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-14 19:18:18 +00:00
|
|
|
-- function M.exp_fader()
|
2021-03-14 02:13:40 +00:00
|
|
|
-- end
|
2021-03-15 02:46:07 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
--[[ ░░▒▒▓█████▓▒▒░░ ]]--
|
2021-03-14 02:13:40 +00:00
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
function M.shrink_resizer(win_id, cnt)
|
|
|
|
if opts.popup.width-cnt > 0 then
|
|
|
|
local config = {
|
|
|
|
relative = "win",
|
|
|
|
row = vim.fn.winline()-1,
|
|
|
|
col = {
|
|
|
|
[false] = vim.fn.wincol()-(opts.popup.width-cnt)/2,
|
|
|
|
[true] = 3 -- temporary
|
|
|
|
},
|
|
|
|
}
|
|
|
|
vim.api.nvim_win_set_width(win_id, opts.popup.width-cnt)
|
|
|
|
vim.api.nvim_win_set_config(win_id, config)
|
|
|
|
return false
|
|
|
|
else return true end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
|
|
|
--[[ ████▓▓▓▒▒▒▒░░░░ ]]--
|
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
function M.slide_resizer(win_id, cnt)
|
|
|
|
if opts.popup.width-cnt > 0 then
|
|
|
|
vim.api.nvim_win_set_width(win_id, opts.popup.width-cnt)
|
|
|
|
return false
|
|
|
|
else return true end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
|
|
|
--[[ ███████████████ ]]--
|
|
|
|
|
|
|
|
function M.empty_resizer(win_id, cnt)
|
|
|
|
if opts.popup.width-cnt > 0 then
|
|
|
|
vim.api.nvim_win_set_width(win_id, opts.popup.width)
|
|
|
|
return false
|
|
|
|
else return true end
|
|
|
|
end
|
|
|
|
|
2021-03-14 19:18:18 +00:00
|
|
|
-- function M.exp_resizer()
|
2021-03-14 02:13:40 +00:00
|
|
|
-- end
|
2021-03-14 19:18:18 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
function M.setup(user_opts)
|
|
|
|
opts = user_opts or {}
|
|
|
|
M.create_autocmds(opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.create_autocmds(opts)
|
2021-03-15 00:31:22 +00:00
|
|
|
vim.cmd("augroup Specs") vim.cmd("autocmd!")
|
2021-03-14 19:18:18 +00:00
|
|
|
if opts.show_jumps then
|
|
|
|
vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()")
|
|
|
|
end
|
|
|
|
vim.cmd("augroup END")
|
|
|
|
end
|
|
|
|
|
2021-03-14 02:13:40 +00:00
|
|
|
|
2021-03-14 19:18:18 +00:00
|
|
|
return M
|