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