Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create empty buffer when first buffer has content #169

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
-- set the shell used for termopen to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc)
vim.o.shell = 'sh'

vim.fn.termopen(full_cmd, {
local success, error = pcall(vim.fn.termopen, full_cmd, {
stdout_buffered = true,
stderr_buffered = true,
on_stdout = function(_, data)
Expand Down Expand Up @@ -210,6 +210,12 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
end
end,
})
if not success then
display_error(full_cmd, {
entrypoint = 'termopen() :: pcall(vim.fn.termopen) error returned',
stderr = error or nil,
})
end

-- restore the original shell after processing termopen
vim.o.shell = p.orig_options.shell
Expand Down
10 changes: 9 additions & 1 deletion lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,15 @@ end
M.launch = function()
local kitty_data = p.kitty_data
vim.schedule(function()
p.bufid = vim.api.nvim_get_current_buf()
local buf_lines = vim.api.nvim_buf_get_lines(0, 0, 1, false)
local no_buf_content = vim.api.nvim_buf_line_count(0) == 1 and buf_lines[1] == ''
if no_buf_content then
p.bufid = vim.api.nvim_get_current_buf()
else
-- buffer must be empty for termopen, dashboard plugins may write to the first buffer before kitty-scrollback.nvim loads
p.bufid = vim.api.nvim_create_buf(true, true)
vim.api.nvim_set_current_buf(p.bufid)
end

ksb_autocmds.load_autocmds()

Expand Down