snailed
/
taolf
Archived
2
0
Fork 0
This commit is contained in:
Luca Bilke 2024-03-06 17:48:50 +01:00
parent 8be2fbcfd8
commit be762b036a
No known key found for this signature in database
GPG Key ID: AD6630D0A1E650AC
2 changed files with 2 additions and 51 deletions

View File

@ -31,7 +31,6 @@ function Lf:new(config)
self:__set_argv()
self.bufnr = 0
self.view_idx = 1
self.action = "drop"
-- Needs to be grabbed here before the terminal buffer is created
self.signcolumn = o.signcolumn
@ -57,10 +56,6 @@ function Lf:start(path)
self:__open_in(path)
self:__set_cmd_wrapper()
self.term.on_open = function(term)
self:__on_open(term)
end
self.term.on_exit = function(term, _, _, _)
self:__callback(term)
uv.fs_unlink(self.tmp_id)
@ -109,7 +104,6 @@ function Lf:__set_cmd_wrapper()
self.tmp_lastdir = os.tmpname()
self.tmp_id = os.tmpname()
-- FIX: non existing file in buffer causes an error message
local selection = self.term.dir
if fn.fnamemodify(self.curfile, ":h") == self.term.dir then
selection = self.curfile
@ -127,35 +121,6 @@ function Lf:__set_cmd_wrapper()
return self
end
---@private
---On open closure to run in the `Terminal`
---@param term Terminal
function Lf:__on_open(term)
self.bufnr = term.bufnr
self.winid = term.window
-- cmd("silent! doautocmd User LfTermEnter")
-- -- Wrap needs to be set, otherwise the window isn't aligned on resize
-- api.nvim_win_call(self.winid, function()
-- vim.wo.showbreak = "NONE"
-- vim.wo.wrap = true
-- vim.wo.sidescrolloff = 0
-- vim.wo.scrolloff = 0
-- vim.wo.scrollbind = false
-- end)
--
-- if self.cfg.tmux then
-- utils.tmux(true)
-- end
--
-- -- Don't know why whenever wrap is set in the terminal, a weird resize happens.
-- -- Because of that, this is needed here.
-- vim.defer_fn(function()
-- cmd("silent! doautoall VimResized")
-- end, 800)
end
local function read_file(path)
-- tonumber(444, 8) == 292
local fd = assert(uv.fs_open(fn.expand(path), "r", 292))
@ -171,21 +136,13 @@ end
---
---@param term Terminal
function Lf:__callback(term)
if (self.action == "cd" or self.action == "lcd")
and uv.fs_stat(self.tmp_lastdir)
then
local last_dir = read_file(self.tmp_lastdir)
if type(last_dir) == "string" then
cmd(("%s %s"):format(self.action, fn.fnameescape(last_dir)))
return
end
elseif uv.fs_stat(self.tmp_sel) then
if uv.fs_stat(self.tmp_sel) then
term:close()
for fname in io.lines(self.tmp_sel) do
local stat = uv.fs_stat(fname)
if type(stat) == "table" then
local fesc = fn.fnameescape(fname)
cmd(("%s %s"):format(self.action, fesc))
cmd(("drop %s"):format(fesc))
local args = table.concat(self.arglist, " ")
if string.len(args) > 0 then
cmd.argadd(args)
@ -195,11 +152,6 @@ function Lf:__callback(term)
end
end
end
-- Reset the action
vim.defer_fn(function()
self.action = "drop"
end, 1)
end
---@private

View File

@ -82,6 +82,5 @@ return M
---@field id number? Current `lf` session id
---@field bufnr number The open file's buffer number
---@field arglist string[] The argument list to neovim
---@field action string The current action to open the file
---@field signcolumn string The signcolumn set by the user before the terminal buffer overrides it
---@field start fun(self, path: string?)