chore: renamed open_float_terminal to terminal and annotated utils.lua
This commit is contained in:
@@ -16,14 +16,14 @@ function M.run()
|
||||
local output = vim.fn.system(table.concat(cmd, "/"))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
utils.terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ function M.run()
|
||||
local output = vim.fn.system(table.concat(cmd, "/"))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
utils.terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ function M.run()
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal({ cmd })
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ end
|
||||
function M.run()
|
||||
local init_lua_path = utils.get_project_root() .. "/lua/" .. utils.get_project_name() .. "/init.lua"
|
||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||
utils.open_float_terminal({ "lua " .. init_lua_path })
|
||||
utils.terminal({ "lua " .. init_lua_path })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ end
|
||||
function M.install_dependency()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or pip_module == "" then return print("Pip canceled") end
|
||||
utils.open_float_terminal({ "pip install " .. pip_module })
|
||||
utils.terminal({ "pip install " .. pip_module })
|
||||
end)
|
||||
end
|
||||
|
||||
function M.run()
|
||||
utils.open_float_terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -17,14 +17,14 @@ function M.run()
|
||||
local output = vim.fn.system(table.concat(cmd))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal({ "cargo run" })
|
||||
utils.terminal({ "cargo run" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+15
-8
@@ -1,16 +1,18 @@
|
||||
local M = {}
|
||||
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@return boolean|nil
|
||||
function M.is_dir(path)
|
||||
local stat = vim.loop.fs_stat(path)
|
||||
return stat and stat.type == "directory"
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.get_project_root()
|
||||
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
||||
|
||||
@@ -18,11 +20,14 @@ function M.get_project_root()
|
||||
return dir
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.get_project_name()
|
||||
local root = M.get_project_root()
|
||||
return vim.fn.fnamemodify(root, ":t")
|
||||
end
|
||||
|
||||
---@param path_segments table
|
||||
---@param content string
|
||||
function M.write_file(path_segments, content)
|
||||
local path = table.concat(path_segments, "/")
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
@@ -31,6 +36,8 @@ function M.write_file(path_segments, content)
|
||||
vim.cmd("edit " .. path)
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param gitignore_lines table
|
||||
function M.init_git(path, gitignore_lines)
|
||||
vim.fn.mkdir(path, "p")
|
||||
vim.fn.system({ "git", "-C", path, "init" })
|
||||
@@ -43,15 +50,15 @@ function M.init_git(path, gitignore_lines)
|
||||
end
|
||||
|
||||
---@param cmd table
|
||||
function M.open_float_terminal(cmd)
|
||||
local presets = require("Polydev.presets")
|
||||
local presets_opts = presets.getPresets(M.opts.preset)
|
||||
---@return integer, integer
|
||||
function M.terminal(cmd)
|
||||
local opts = require("Polydev.presets").getPresets(M.opts.preset)
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
|
||||
local width = math.max(1, math.floor(ui.width * 0.9) - presets_opts.left_padding - presets_opts.right_padding)
|
||||
local height = math.max(1, math.floor(ui.height * 0.9) - presets_opts.top_padding - presets_opts.bottom_padding)
|
||||
local row = math.floor((ui.height - height) / 2) + presets_opts.top_padding
|
||||
local col = math.floor((ui.width - width) / 2) + presets_opts.left_padding
|
||||
local width = math.max(1, math.floor(ui.width * 0.9) - opts.left_padding - opts.right_padding)
|
||||
local height = math.max(1, math.floor(ui.height * 0.9) - opts.top_padding - opts.bottom_padding)
|
||||
local row = math.floor((ui.height - height) / 2) + opts.top_padding
|
||||
local col = math.floor((ui.width - width) / 2) + opts.left_padding
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
|
||||
Reference in New Issue
Block a user