diff options
| author | Aotrix <[email protected]> | 2026-04-17 01:10:09 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-04-17 01:10:09 +0200 |
| commit | 6efa65f6e6f84f65bdebd96698821b7f98056f8c (patch) | |
| tree | 80a57d3ee7e1bdd172bff18423f4ca982e2dd3e9 /lua/aotrix/build.lua | |
| parent | 1602167e8c1638b2431cc6ad30caf90cab3773f0 (diff) | |
Add build command input
Diffstat (limited to 'lua/aotrix/build.lua')
| -rw-r--r-- | lua/aotrix/build.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua new file mode 100644 index 0000000..b5dc3bb --- /dev/null +++ b/lua/aotrix/build.lua @@ -0,0 +1,54 @@ +local BUILD_COMMAND = "" + +---@return nil +function createFloatingWindow() + local max_height = vim.api.nvim_win_get_height(0) + local max_width = vim.api.nvim_win_get_width(0) + local window_height = math.floor(max_height / 2) + local window_width = math.floor(max_width / 2) + local window_buffer = vim.api.nvim_create_buf(false, true) + vim.api.nvim_open_win(window_buffer, true, { + border = "rounded", + style = "minimal", + relative = "editor", + noautocmd = true, + height = window_height, + width = window_width, + col = math.floor((max_width - window_width) / 2), + row = math.floor((max_height - window_height) / 2) + }) + return window_buffer +end + +---@return nil +function createFloatingTerminal() + createFloatingWindow() + vim.cmd.term() + vim.cmd.startinsert() +end + +---@param command string +---@return nil +function executeCommandInTerminal(command) + local channel = vim.bo.channel + -- 'clear' is used to hide the command + local exit_message = "\nPress enter to exit..." + vim.api.nvim_chan_send(channel, + "clear && " .. command .. "; echo '" .. exit_message .. + "' && read -s && exit" .. "\n") +end + +function setBuildCommand() + BUILD_COMMAND = vim.fn.input("Enter compile command: ", BUILD_COMMAND) +end + +function build() + if string.len(BUILD_COMMAND) == 0 then setBuildCommand() end + if string.len(BUILD_COMMAND) > 0 then + createFloatingTerminal() + executeCommandInTerminal(BUILD_COMMAND) + end +end + +vim.keymap.set("n", "mc", setBuildCommand) +vim.keymap.set("n", "mt", build) |
