mirror of
https://github.com/NotAShelf/specs.nvim.git
synced 2024-12-27 05:02:24 +00:00
Merge pull request #18 from tingham/feature/inline-opts
Feature/inline opts
This commit is contained in:
commit
36ebdf4858
2 changed files with 26 additions and 7 deletions
|
@ -47,6 +47,7 @@ require('specs').setup{
|
|||
- Toggle Specs on/off
|
||||
|
||||
Faders:
|
||||
- sinus_fader `⌣/⌢\⌣/⌢\⌣/⌢\⌣/⌢`
|
||||
- linear_fader `▁▂▂▃▃▄▄▅▅▆▆▇▇██`
|
||||
- exp_fader `▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇`
|
||||
|
||||
|
@ -93,6 +94,9 @@ vim.api.nvim_set_keymap('n', '<C-b>', ':lua require("specs").show_specs()', { no
|
|||
-- You can even bind it to search jumping and more, example:
|
||||
vim.api.nvim_set_keymap('n', 'n', 'n:lua require("specs").show_specs()<CR>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', 'N', 'N:lua require("specs").show_specs()<CR>', { noremap = true, silent = true })
|
||||
|
||||
-- Or maybe you do a lot of screen-casts and want to call attention to a specific line of code:
|
||||
vim.api.nvim_set_keymap('n', '<leader>v', ':lua require("specs").show_specs({width = 97, winhl = "Search", delay_ms = 610, inc_ms = 21})<CR>', { noremap = true, silent = true })
|
||||
```
|
||||
|
||||
## Planned Features
|
||||
|
|
|
@ -40,33 +40,39 @@ function M.should_show_specs(start_win_id)
|
|||
return true
|
||||
end
|
||||
|
||||
function M.show_specs()
|
||||
function M.show_specs(popup)
|
||||
local start_win_id = vim.api.nvim_get_current_win()
|
||||
|
||||
if not M.should_show_specs(start_win_id) then
|
||||
return
|
||||
end
|
||||
|
||||
if popup == nil then
|
||||
popup = {}
|
||||
end
|
||||
|
||||
local _opts = vim.tbl_deep_extend("force", opts, {popup = popup})
|
||||
|
||||
local cursor_col = vim.fn.wincol()-1
|
||||
local cursor_row = vim.fn.winline()-1
|
||||
local bufh = vim.api.nvim_create_buf(false, true)
|
||||
local win_id = vim.api.nvim_open_win(bufh, false, {
|
||||
relative='win',
|
||||
relative= 'win',
|
||||
width = 1,
|
||||
height = 1,
|
||||
col = cursor_col,
|
||||
row = cursor_row,
|
||||
style = 'minimal'
|
||||
})
|
||||
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, 'winhl', 'Normal:'.. _opts.popup.winhl)
|
||||
vim.api.nvim_win_set_option(win_id, "winblend", _opts.popup.blend)
|
||||
|
||||
local cnt = 0
|
||||
local config = vim.api.nvim_win_get_config(win_id)
|
||||
local timer = vim.loop.new_timer()
|
||||
local closed = false
|
||||
|
||||
vim.loop.timer_start(timer, opts.popup.delay_ms, opts.popup.inc_ms, vim.schedule_wrap(function()
|
||||
vim.loop.timer_start(timer, _opts.popup.delay_ms, _opts.popup.inc_ms, vim.schedule_wrap(function()
|
||||
if closed or vim.api.nvim_get_current_win() ~= start_win_id then
|
||||
if not closed then
|
||||
pcall(vim.loop.close, timer)
|
||||
|
@ -81,8 +87,8 @@ function M.show_specs()
|
|||
end
|
||||
|
||||
if vim.api.nvim_win_is_valid(win_id) then
|
||||
local bl = opts.popup.fader(opts.popup.blend, cnt)
|
||||
local dm = opts.popup.resizer(opts.popup.width, cursor_col, cnt)
|
||||
local bl = _opts.popup.fader(_opts.popup.blend, cnt)
|
||||
local dm = _opts.popup.resizer(_opts.popup.width, cursor_col, cnt)
|
||||
|
||||
if bl ~= nil then
|
||||
vim.api.nvim_win_set_option(win_id, "winblend", bl)
|
||||
|
@ -99,6 +105,7 @@ function M.show_specs()
|
|||
cnt = cnt+1
|
||||
end
|
||||
end))
|
||||
|
||||
end
|
||||
|
||||
--[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]--
|
||||
|
@ -109,6 +116,14 @@ function M.linear_fader(blend, cnt)
|
|||
else return nil end
|
||||
end
|
||||
|
||||
--[[ ⌣/⌢\⌣/⌢\⌣/⌢\⌣/⌢\ ]]--
|
||||
|
||||
function M.sinus_fader(blend, cnt)
|
||||
if cnt <= 100 then
|
||||
return math.ceil((math.sin(cnt * (1 / blend)) * 0.5 + 0.5) * 100)
|
||||
else return nil end
|
||||
end
|
||||
|
||||
|
||||
--[[ ▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇ ]]--
|
||||
|
||||
|
|
Loading…
Reference in a new issue