From 0450c1008cc7365e5d1a2b0fbdeff32586f3a22f Mon Sep 17 00:00:00 2001 From: edluffy Date: Sun, 14 Mar 2021 02:13:40 +0000 Subject: [PATCH] Add first faders/resizers --- lua/specs/init.lua | 66 ++++++++++++++++++++++++++++++++++++++++++++++ plugin/specs.vim | 26 ++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 lua/specs/init.lua create mode 100644 plugin/specs.vim diff --git a/lua/specs/init.lua b/lua/specs/init.lua new file mode 100644 index 0000000..62bd4c0 --- /dev/null +++ b/lua/specs/init.lua @@ -0,0 +1,66 @@ +local specs = {} + +function specs.show_specs(user_opts) + local opts = user_opts or {} + + local row = vim.fn.winline()-1 + local col = vim.fn.wincol() + local bufh = vim.api.nvim_create_buf(false, true) + win_id = vim.api.nvim_open_win(bufh, false, { + relative='win', + width = opts.width*2 + 1, + height = 1, + col = col, + row = row, + style = 'minimal' + }) + vim.api.nvim_win_set_option(win_id, "winblend", opts.blend) + + local can_fade = true + local can_resize = true + local timer = vim.loop.new_timer() + vim.loop.timer_start(timer, opts.delay_ms, opts.inc_ms, vim.schedule_wrap(function() + if vim.api.nvim_win_is_valid(win_id) then + if can_fade then can_fade = opts.fader(win_id) end + if can_resize then can_resize = opts.resizer(win_id) end + if not (can_blend or can_resize) then + vim.loop.close(timer) + vim.api.nvim_win_close(win_id, true) + print("Timer done") + end + end + end)) +end + +-- Used as the default fader +function specs.linear_fader(win_id) + local blend = vim.api.nvim_win_get_option(win_id, "winblend") + vim.api.nvim_win_set_option(win_id, "winblend", blend+1) + return (blend+1 < 100) +end + +local function pulse_fader(win_id) +end + +-- local function exp_fader() +-- end + +function specs.shrink_resizer(win_id) + local config = vim.api.nvim_win_get_config(win_id) + config['width'] = config['width']-1 + config['col'][false] = vim.fn.wincol()-config['width']/2 + vim.api.nvim_win_set_config(win_id, config) + return (config['width']-1 > 0) +end + +function specs.slide_resizer(win_id) + local config = vim.api.nvim_win_get_config(win_id) + config['width'] = config['width']-1 + vim.api.nvim_win_set_config(win_id, config) + return (config['width']-1 > 0) +end + +-- local function exp_resizer() +-- end + +return specs diff --git a/plugin/specs.vim b/plugin/specs.vim new file mode 100644 index 0000000..a33b916 --- /dev/null +++ b/plugin/specs.vim @@ -0,0 +1,26 @@ +fun! Specs() + " remember to remove this line later ;) + lua for k in pairs(package.loaded) do if k:match("^specs") then package.loaded[k] = nil end end + lua require('specs').show_specs({ delay_ms = 1, inc_ms = 10, blend = 10, width = 20, fader=require('specs').linear_fader, resizer=require('specs').shrink_resizer }) +endfun + + " e.g: + " require('specs').specs_popup({ + " delay = ..., + " reps = ..., + " blend = ..., + " width = ..., + " fader = require('specs').linear_fader(), + " resizer = require('specs').shrink_resizer() + " colorizer = ..., + " }) + + + " pre-packaged opts could come as 'styles', which also have opts + " themselves: + " require('specs').specs_popup(require('specs').blink_style({ })) + +augroup Specs + autocmd! +augroup END +