summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-09-07 10:47:11 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-09-07 10:47:11 -0400
commitdffcef9470e0fff88d10a1e5b6d195980b977f4c (patch)
treecb9c4b0dcd537f925956c2974bcc35af7c62695f /lua
parent1b04f99e42cfa331e316c227ed1fd66cc22279b8 (diff)
fix: Close termopen jobs when done
TODO: Still need to fix the rest of em. And I see lots of repeated code... we will need to fix that. Also adjusted some bat options.
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/previewers.lua18
1 files changed, 14 insertions, 4 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index 5f9268d..694a1ba 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -10,7 +10,10 @@ local previewers = {}
local Previewer = {}
Previewer.__index = Previewer
-local bat_options = " --style=grid --paging=always "
+-- TODO: Should play with these some more, ty @clason
+local bat_options = " --style=numbers --plain --paging=never --pager=cat"
+bat_options = " --style=grid --plain --pager=cat "
+
local previewer_ns = vim.api.nvim_create_namespace('telescope.previewers')
-- --terminal-width=%s
@@ -173,14 +176,21 @@ previewers.cat = defaulter(function(opts)
setup = function()
local command_string = "cat '%s'"
if 1 == vim.fn.executable("bat") then
- command_string = "bat '%s' --style=grid --paging=always"
+ command_string = "bat '%s' " .. bat_options
end
return {
- command_string = command_string
+ command_string = command_string,
+ termopen_id = nil,
}
end,
+ teardown = function(self)
+ if self.state.termopen_id then
+ pcall(vim.fn.chanclose, self.state.termopen_id)
+ end
+ end,
+
preview_fn = function(self, entry, status)
local bufnr = vim.api.nvim_create_buf(false, true)
@@ -195,7 +205,7 @@ previewers.cat = defaulter(function(opts)
term_opts.cwd = opts.cwd
with_preview_window(status, function()
- vim.fn.termopen(string.format(self.state.command_string, path), term_opts)
+ self.state.termopen_id = vim.fn.termopen(string.format(self.state.command_string, path), term_opts)
end)
vim.api.nvim_buf_set_name(bufnr, tostring(bufnr))