summaryrefslogtreecommitdiff
path: root/lua/telescope/previewers.lua
diff options
context:
space:
mode:
authorhaorenW1025 <whz861025@gmail.com>2020-09-17 00:20:45 +0800
committerGitHub <noreply@github.com>2020-09-16 12:20:45 -0400
commit7d1a8292b6c7db7401af05f75e6d9992fc8ed28a (patch)
treed0d3a0c34b5ad8e70583c2a1c8c67d87abda89a5 /lua/telescope/previewers.lua
parent9bdf5b3d4af99b76d3cd25466af708d57d6a1483 (diff)
feat: add scrolling in preview window (#47)
* feat: add scrolling in preview window refactor into two layers * remove redundant code * add error message for scroll_fn and send_input * consider count for preview scrolling
Diffstat (limited to 'lua/telescope/previewers.lua')
-rw-r--r--lua/telescope/previewers.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index 5798bac..462b65e 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -11,7 +11,7 @@ local Previewer = {}
Previewer.__index = Previewer
-- TODO: Should play with these some more, ty @clason
-local bat_options = " --style=plain --paging=never --color=always "
+local bat_options = " --style=plain --color=always "
local previewer_ns = vim.api.nvim_create_namespace('telescope.previewers')
@@ -28,6 +28,8 @@ function Previewer:new(opts)
state = nil,
_setup_func = opts.setup,
_teardown_func = opts.teardown,
+ _send_input = opts.send_input,
+ _scroll_fn = opts.scroll_fn,
preview_fn = opts.preview_fn,
}, Previewer)
end
@@ -55,6 +57,22 @@ function Previewer:teardown()
end
end
+function Previewer:send_input(input)
+ if self._send_input then
+ self:_send_input(input)
+ else
+ vim.api.nvim_err_writeln("send_input is not defined for this previewer")
+ end
+end
+
+function Previewer:scroll_fn(direction)
+ if self._scroll_fn then
+ self:_scroll_fn(direction)
+ else
+ vim.api.nvim_err_writeln("scroll_fn is not defined for this previewer")
+ end
+end
+
previewers.new = function(...)
return Previewer:new(...)
end
@@ -186,6 +204,22 @@ previewers.cat = defaulter(function(opts)
}
end,
+ send_input = function(self, input)
+ termcode = vim.api.nvim_replace_termcodes(input, true, false, true)
+ if self.state.termopen_id then
+ pcall(vim.fn.chansend, self.state.termopen_id, termcode)
+ end
+ end,
+
+ scroll_fn = function(self, direction)
+ if not self.state then
+ return
+ end
+ if direction > 0 then input = "d" else input = "u" end
+ local count = math.abs(direction)
+ self:send_input(count..input)
+ end,
+
teardown = function(self)
if not self.state then
return