From dffcef9470e0fff88d10a1e5b6d195980b977f4c Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 7 Sep 2020 10:47:11 -0400 Subject: [PATCH] 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. --- lua/telescope/previewers.lua | 18 ++++++++++++++---- 1 file 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))