feat: set specs ft

This commit is contained in:
raf 2024-05-19 02:31:49 +03:00
parent 2743e412bb
commit 30a4c18276
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29

View file

@ -7,7 +7,7 @@ local au_toggle
function M.on_cursor_moved() function M.on_cursor_moved()
local cur = vim.fn.winline() + vim.api.nvim_win_get_position(0)[1] local cur = vim.fn.winline() + vim.api.nvim_win_get_position(0)[1]
if old_cur then if old_cur then
local jump = math.abs(cur-old_cur) local jump = math.abs(cur - old_cur)
if jump >= opts.min_jump then if jump >= opts.min_jump then
M.show_specs() M.show_specs()
end end
@ -55,20 +55,23 @@ function M.show_specs(popup)
popup = {} popup = {}
end end
local _opts = vim.tbl_deep_extend("force", opts, {popup = popup}) local _opts = vim.tbl_deep_extend("force", opts, { popup = popup })
local cursor_col = vim.fn.wincol()-1 local cursor_col = vim.fn.wincol() - 1
local cursor_row = vim.fn.winline()-1 local cursor_row = vim.fn.winline() - 1
local bufh = vim.api.nvim_create_buf(false, true) local bufh = vim.api.nvim_create_buf(false, true)
local win_id = vim.api.nvim_open_win(bufh, false, { local win_id = vim.api.nvim_open_win(bufh, false, {
relative= 'win', relative = 'win',
width = 1, width = 1,
height = 1, height = 1,
col = cursor_col, col = cursor_col,
row = cursor_row, row = cursor_row,
style = 'minimal' style = 'minimal',
noautocmd = true
}) })
vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:'.. _opts.popup.winhl)
vim.api.nvim_set_option_value('filetype', 'specs.nvim', { buf = bufh })
vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:' .. _opts.popup.winhl)
vim.api.nvim_win_set_option(win_id, "winblend", _opts.popup.blend) vim.api.nvim_win_set_option(win_id, "winblend", _opts.popup.blend)
local cnt = 0 local cnt = 0
@ -106,79 +109,95 @@ function M.show_specs(popup)
vim.loop.close(timer) vim.loop.close(timer)
vim.api.nvim_win_close(win_id, true) vim.api.nvim_win_close(win_id, true)
end end
cnt = cnt+1 cnt = cnt + 1
end end
end)) end))
end end
--[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]-- --[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]
--
function M.linear_fader(blend, cnt) function M.linear_fader(blend, cnt)
if blend + cnt <= 100 then if blend + cnt <= 100 then
return cnt return cnt
else return nil end else
return nil
end
end end
--[[ ⌣/⌢\⌣/⌢\⌣/⌢\⌣/⌢\ ]]-- --[[ ⌣/⌢\⌣/⌢\⌣/⌢\⌣/⌢\ ]]
--
function M.sinus_fader(blend, cnt) function M.sinus_fader(blend, cnt)
if cnt <= 100 then if cnt <= 100 then
return math.ceil((math.sin(cnt * (1 / blend)) * 0.5 + 0.5) * 100) return math.ceil((math.sin(cnt * (1 / blend)) * 0.5 + 0.5) * 100)
else return nil end else
return nil
end
end end
--[[ ▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇ ]]
--[[ ▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇ ]]-- --
function M.exp_fader(blend, cnt) function M.exp_fader(blend, cnt)
if blend + math.floor(math.exp(cnt/10)) <= 100 then if blend + math.floor(math.exp(cnt / 10)) <= 100 then
return blend + math.floor(math.exp(cnt/10)) return blend + math.floor(math.exp(cnt / 10))
else return nil end else
return nil
end
end end
--[[ ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ ]]
--[[ ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ ]]-- --
function M.pulse_fader(blend, cnt) function M.pulse_fader(blend, cnt)
if cnt < (100-blend)/2 then if cnt < (100 - blend) / 2 then
return cnt return cnt
elseif cnt < 100-blend then elseif cnt < 100 - blend then
return 100-cnt return 100 - cnt
else return nil end else
return nil
end
end end
--[[ ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ]]-- --[[ ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ]]
--
function M.empty_fader(_, _) function M.empty_fader(_, _)
return nil return nil
end end
--[[ ░░▒▒▓█████▓▒▒░░ ]]
--[[ ░░▒▒▓█████▓▒▒░░ ]]-- --
function M.shrink_resizer(width, ccol, cnt) function M.shrink_resizer(width, ccol, cnt)
if width-cnt > 0 then if width - cnt > 0 then
return {width-cnt, ccol-(width-cnt)/2 + 1} return { width - cnt, ccol - (width - cnt) / 2 + 1 }
else return nil end else
return nil
end
end end
--[[ ████▓▓▓▒▒▒▒░░░░ ]]
--[[ ████▓▓▓▒▒▒▒░░░░ ]]-- --
function M.slide_resizer(width, ccol, cnt) function M.slide_resizer(width, ccol, cnt)
if width-cnt > 0 then if width - cnt > 0 then
return {width-cnt, ccol} return { width - cnt, ccol }
else return nil end else
return nil
end
end end
--[[ ███████████████ ]]
--[[ ███████████████ ]]-- --
function M.empty_resizer(width, ccol, cnt) function M.empty_resizer(width, ccol, cnt)
if cnt < 100 then if cnt < 100 then
return {width, ccol - width/2} return { width, ccol - width / 2 }
else return nil end else
return nil
end
end end
local DEFAULT_OPTS = { local DEFAULT_OPTS = {
@ -213,7 +232,8 @@ function M.toggle()
end end
function M.create_autocmds() function M.create_autocmds()
vim.cmd("augroup Specs") vim.cmd("autocmd!") vim.cmd("augroup Specs")
vim.cmd("autocmd!")
if opts.show_jumps then if opts.show_jumps then
vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()") vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()")
end end
@ -222,7 +242,8 @@ function M.create_autocmds()
end end
function M.clear_autocmds() function M.clear_autocmds()
vim.cmd("augroup Specs") vim.cmd("autocmd!") vim.cmd("augroup Specs")
vim.cmd("autocmd!")
vim.cmd("augroup END") vim.cmd("augroup END")
au_toggle = false au_toggle = false
end end