From 35d5b6a871d20aaa3926834db604860b7aea59c3 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Fri, 14 Mar 2025 14:29:25 -0400 Subject: [PATCH] Update rust.lua --- lua/Polydev/rust.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lua/Polydev/rust.lua b/lua/Polydev/rust.lua index 60f6efe..87ad3a9 100644 --- a/lua/Polydev/rust.lua +++ b/lua/Polydev/rust.lua @@ -131,7 +131,28 @@ end function M.run() local root = M.get_project_root() if not root then return print("Error: Project root not found.") end - M.open_float_terminal("cargo run") + + -- Open the floating terminal with the command `cargo run` + local term_buf, term_win = M.open_float_terminal("cargo run") + + -- Make the terminal buffer writable and wait for the output + vim.api.nvim_buf_set_option(term_buf, "modifiable", true) + + -- Get the output of the `cargo run` command and display it + local output = vim.fn.system("cargo run") + local success = vim.v.shell_error == 0 + + -- Set the output in the terminal buffer + vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, vim.list_extend( + { success and "Program ran successfully!" or "Error during run:" }, + vim.split(output, "\n", { trimempty = true }) + )) + + -- Set the terminal buffer as non-modifiable again + vim.api.nvim_buf_set_option(term_buf, "modifiable", false) + + -- Optionally, ensure the terminal window is focused + vim.api.nvim_set_current_win(term_win) end return M