some nice fixes
This commit is contained in:
@@ -41,8 +41,23 @@ end
|
||||
|
||||
function M.configure_cmake(build_type)
|
||||
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(
|
||||
{ M.find_cmake(), "-DCMAKE_BUILD_TYPE=" .. build_type, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", ".." },
|
||||
{ M.find_cmake(), unpack(cmake_args) },
|
||||
{ cwd = "build" }
|
||||
)
|
||||
end
|
||||
|
||||
@@ -11,15 +11,38 @@ function M.float_terminal(cmd, opts)
|
||||
style = "minimal", relative = "editor",
|
||||
width = width, height = height, row = row, col = col,
|
||||
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 win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||
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, {
|
||||
cwd = opts.cwd, -- <= important
|
||||
cwd = opts.cwd,
|
||||
on_stdout = function(...) scroll_bottom() end,
|
||||
on_stderr = function(...) scroll_bottom() end,
|
||||
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)
|
||||
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 })
|
||||
|
||||
Reference in New Issue
Block a user