some nice fixes

This commit is contained in:
2025-11-19 13:33:11 -03:00
parent 92b3bd1af3
commit e5a08226b7
2 changed files with 41 additions and 3 deletions

View File

@@ -41,8 +41,23 @@ end
function M.configure_cmake(build_type) function M.configure_cmake(build_type)
vim.fn.mkdir("build", "p") vim.fn.mkdir("build", "p")
local cmake_module_path = vim.fn.getenv("CMAKE_MODULE_PATH")
local module_path_arg = ""
if cmake_module_path ~= nil and cmake_module_path ~= "" then
module_path_arg = "-DCMAKE_MODULE_PATH=" .. cmake_module_path
end
local cmake_args = {
module_path_arg,
"-DCMAKE_BUILD_TYPE=" .. build_type,
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
".."
}
float_term( float_term(
{ M.find_cmake(), "-DCMAKE_BUILD_TYPE=" .. build_type, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", ".." }, { M.find_cmake(), unpack(cmake_args) },
{ cwd = "build" } { cwd = "build" }
) )
end end

View File

@@ -11,15 +11,38 @@ function M.float_terminal(cmd, opts)
style = "minimal", relative = "editor", style = "minimal", relative = "editor",
width = width, height = height, row = row, col = col, width = width, height = height, row = row, col = col,
border = opts.border or "rounded", border = opts.border or "rounded",
-- Set the buffer for the new window
buf = buf,
}) })
-- --- START MODIFICATION ---
-- Format the command as a string for display
local cmd_display
if type(cmd) == 'table' then
cmd_display = table.concat(cmd, " ")
else
cmd_display = cmd
end
-- Write the command string to the top of the buffer
vim.api.nvim_buf_set_lines(buf, 0, 0, false, {
"--- RUNNING COMMAND: " .. cmd_display .. " ---",
"", -- Add an empty line for separation
})
-- --- END MODIFICATION ---
local function scroll_bottom() local function scroll_bottom()
local win = vim.api.nvim_get_current_win() local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0}) vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
end end
-- We need to ensure the terminal starts in the correct buffer
vim.api.nvim_set_current_buf(buf)
local job = vim.fn.termopen(cmd, { local job = vim.fn.termopen(cmd, {
cwd = opts.cwd, -- <= important cwd = opts.cwd,
on_stdout = function(...) scroll_bottom() end, on_stdout = function(...) scroll_bottom() end,
on_stderr = function(...) scroll_bottom() end, on_stderr = function(...) scroll_bottom() end,
on_exit = function(_, code, _) on_exit = function(_, code, _)
@@ -27,7 +50,7 @@ function M.float_terminal(cmd, opts)
vim.notify(("command exited %d"):format(code), code == 0 and vim.log.levels.INFO or vim.log.levels.ERROR) vim.notify(("command exited %d"):format(code), code == 0 and vim.log.levels.INFO or vim.log.levels.ERROR)
end) end)
end, end,
env = opts.env, -- e.g. env = { PATH = os.getenv("PATH") } env = opts.env,
}) })
vim.keymap.set("n", "q", "<cmd>bd!<CR>", { buffer = buf, silent = true }) vim.keymap.set("n", "q", "<cmd>bd!<CR>", { buffer = buf, silent = true })