From c61eac8eaf8262833ce9824538fa3e3732a3bf1c Mon Sep 17 00:00:00 2001 From: Thomas Ingham Date: Wed, 31 Aug 2022 14:16:46 -0400 Subject: [PATCH] Actually made it work.. nice. --- README.md | 4 ++++ lua/specs/init.lua | 41 ++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 8576fcb..2ca91ae 100644 --- a/README.md +++ b/README.md @@ -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', '', ':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()', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'N', 'N:lua require("specs").show_specs()', { 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', 'v', ':lua require("specs").show_specs({width = 97, winhl = "Search", delay_ms = 610, inc_ms = 21})', { noremap = true, silent = true }) ``` ## Planned Features diff --git a/lua/specs/init.lua b/lua/specs/init.lua index d3dad3b..e72ee08 100644 --- a/lua/specs/init.lua +++ b/lua/specs/init.lua @@ -47,28 +47,11 @@ function M.show_specs(popup) return end - local function dcopy (t) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - if popup == nil then - popup = opts.popup + popup = {} end - local originalOptions = deep_copy(opts) - local instanceOptions = deep_copy(opts) - instanceOptions.popup = popup + local _opts = vim.tbl_deep_extend("force", opts, {popup = popup}) local cursor_col = vim.fn.wincol()-1 local cursor_row = vim.fn.winline()-1 @@ -81,15 +64,15 @@ function M.show_specs(popup) row = cursor_row, style = 'minimal' }) - vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:'.. instanceOptions.popup.winhl) - vim.api.nvim_win_set_option(win_id, "winblend", instanceOptions.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, instanceOptions.popup.delay_ms, instanceOptions.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) @@ -98,15 +81,14 @@ function M.show_specs(popup) -- Callbacks might stack up before the timer actually gets closed, track that state -- internally here instead closed = true - opts = originalOptions end return end if vim.api.nvim_win_is_valid(win_id) then - local bl = instanceOptions.popup.fader(instanceOptions.popup.blend, cnt) - local dm = instanceOptions.popup.resizer(instanceOptions.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) @@ -123,6 +105,7 @@ function M.show_specs(popup) cnt = cnt+1 end end)) + end --[[ ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██ ]]-- @@ -133,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 + --[[ ▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇ ]]--