2021-03-14 19:18:18 +00:00
|
|
|
local M = {}
|
2021-03-17 01:57:41 +00:00
|
|
|
local opts = {}
|
|
|
|
|
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-17 17:29:19 +00:00
|
|
|
local cursor_col = vim.fn.wincol()-1
|
|
|
|
local cursor_row = vim.fn.winline()-1
|
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-17 17:29:19 +00:00
|
|
|
col = cursor_col,
|
|
|
|
row = cursor_row,
|
2021-03-14 02:13:40 +00:00
|
|
|
style = 'minimal'
|
|
|
|
})
|
2021-03-23 23:31:18 +00:00
|
|
|
vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:'.. opts.popup.winhl)
|
2021-03-17 17:29:19 +00:00
|
|
|
vim.api.nvim_win_set_option(win_id, "winblend", opts.popup.blend)
|
2021-03-14 02:13:40 +00:00
|
|
|
|
2021-03-23 23:31:18 +00:00
|
|
|
|
|
|
|
|
2021-03-15 00:31:22 +00:00
|
|
|
local cnt = 0
|
2021-03-17 17:29:19 +00:00
|
|
|
local config = vim.api.nvim_win_get_config(win_id)
|
2021-03-14 02:13:40 +00:00
|
|
|
local timer = vim.loop.new_timer()
|
2021-03-17 17:29:19 +00:00
|
|
|
|
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-17 17:46:39 +00:00
|
|
|
local bl = opts.popup.fader(opts.popup.blend, cnt)
|
|
|
|
local dm = opts.popup.resizer(opts.popup.width, cursor_col, cnt)
|
2021-03-15 00:31:22 +00:00
|
|
|
|
2021-03-17 17:29:19 +00:00
|
|
|
if bl ~= nil then
|
|
|
|
vim.api.nvim_win_set_option(win_id, "winblend", bl)
|
|
|
|
end
|
|
|
|
if dm ~= nil then
|
|
|
|
config["col"][false] = dm[2]
|
|
|
|
vim.api.nvim_win_set_config(win_id, config)
|
|
|
|
vim.api.nvim_win_set_width(win_id, dm[1])
|
|
|
|
end
|
|
|
|
if bl == nil and dm == nil then -- Done blending and resizing
|
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
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
--[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]--
|
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.linear_fader(blend, cnt)
|
|
|
|
if blend + cnt <= 100 then
|
2021-03-17 17:29:19 +00:00
|
|
|
return cnt
|
|
|
|
else return nil end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
2021-03-15 16:35:25 +00:00
|
|
|
--[[ ▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇ ]]--
|
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.exp_fader(blend, cnt)
|
|
|
|
if blend + math.floor(math.exp(cnt/10)) <= 100 then
|
|
|
|
return blend + math.floor(math.exp(cnt/10))
|
2021-03-17 17:29:19 +00:00
|
|
|
else return nil end
|
2021-03-15 16:35:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
--[[ ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ ]]--
|
2021-03-17 17:29:19 +00:00
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.pulse_fader(blend, cnt)
|
|
|
|
if cnt < (100-blend)/2 then
|
2021-03-17 17:29:19 +00:00
|
|
|
return cnt
|
2021-03-17 17:46:39 +00:00
|
|
|
elseif cnt < 100-blend then
|
2021-03-17 17:29:19 +00:00
|
|
|
return 100-cnt
|
|
|
|
else return nil end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[ ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ]]--
|
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.empty_fader(blend, cnt)
|
2021-03-17 17:29:19 +00:00
|
|
|
return nil
|
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-17 17:46:39 +00:00
|
|
|
function M.shrink_resizer(width, ccol, cnt)
|
|
|
|
if width-cnt > 0 then
|
|
|
|
return {width-cnt, ccol-(width-cnt)/2 + 1}
|
2021-03-17 17:29:19 +00:00
|
|
|
else return nil end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
|
|
|
--[[ ████▓▓▓▒▒▒▒░░░░ ]]--
|
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.slide_resizer(width, ccol, cnt)
|
|
|
|
if width-cnt > 0 then
|
|
|
|
return {width-cnt, ccol}
|
2021-03-17 17:29:19 +00:00
|
|
|
else return nil end
|
2021-03-14 02:13:40 +00:00
|
|
|
end
|
|
|
|
|
2021-03-15 02:46:07 +00:00
|
|
|
|
|
|
|
--[[ ███████████████ ]]--
|
|
|
|
|
2021-03-17 17:46:39 +00:00
|
|
|
function M.empty_resizer(width, ccol, cnt)
|
2021-03-17 17:29:19 +00:00
|
|
|
if cnt < 100 then
|
2021-03-17 17:46:39 +00:00
|
|
|
return {width, ccol - width/2}
|
2021-03-17 17:29:19 +00:00
|
|
|
else return nil end
|
2021-03-15 02:46:07 +00:00
|
|
|
end
|
|
|
|
|
2021-03-17 01:57:41 +00:00
|
|
|
local DEFAULT_OPTS = {
|
|
|
|
show_jumps = true,
|
|
|
|
min_jump = 30,
|
|
|
|
popup = {
|
|
|
|
delay_ms = 10,
|
|
|
|
inc_ms = 5,
|
|
|
|
blend = 10,
|
|
|
|
width = 20,
|
2021-03-23 23:31:18 +00:00
|
|
|
winhl = "PMenu",
|
2021-03-17 01:57:41 +00:00
|
|
|
fader = M.exp_fader,
|
|
|
|
resizer = M.shrink_resizer
|
|
|
|
}
|
|
|
|
}
|
2021-03-14 19:18:18 +00:00
|
|
|
|
|
|
|
function M.setup(user_opts)
|
2021-03-17 01:57:41 +00:00
|
|
|
opts = vim.tbl_deep_extend("force", DEFAULT_OPTS, user_opts)
|
|
|
|
M.create_autocmds()
|
2021-03-14 19:18:18 +00:00
|
|
|
end
|
|
|
|
|
2021-03-17 01:57:41 +00:00
|
|
|
function M.create_autocmds()
|
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
|