rework: open_float_terminal uses table instead of string
fix: all languages now use proper terminal setup
This commit is contained in:
@@ -1,31 +1,21 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("c"), opts or {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
end
|
||||
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("c"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CRun", M.run, {})
|
||||
|
||||
if M.keybinds.CRun then
|
||||
vim.keymap.set("n", M.keybinds.CRun, ":CRun<CR>", { silent = true })
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
function M.run()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
local cmd = { "cd " .. root, "build", " && cmake --build ." }
|
||||
local output = vim.fn.system(table.concat(cmd, "/"))
|
||||
|
||||
if not success then
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
@@ -33,7 +23,7 @@ function M.run()
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. utils.get_project_name())
|
||||
utils.open_float_terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("cpp"), opts or {})
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("cpp"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CppRun", M.run, {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
end
|
||||
|
||||
if M.keybinds.CppRun then
|
||||
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
function M.run()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
local cmd = { "cd " .. root, "build", " && cmake --build ." }
|
||||
local output = vim.fn.system(table.concat(cmd, "/"))
|
||||
|
||||
if not success then
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
@@ -32,7 +23,7 @@ function M.run()
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal("cd " .. build_dir .. " && ./" .. utils.get_project_name())
|
||||
utils.open_float_terminal({ "cd " .. root, "build" .. " && .", utils.get_project_name() })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {})
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), user_opts or {})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,39 +1,29 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("java"), opts or {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
end
|
||||
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("java"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavaRun", M.run, {})
|
||||
|
||||
if M.keybinds.JavaRun then
|
||||
vim.keymap.set("n", M.keybinds.JavaRun, ":JavaRun<CR>", { silent = true })
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
function M.run()
|
||||
local root = utils.get_project_root()
|
||||
local out_dir = root .. "/build"
|
||||
|
||||
local cmd = string.format("javac -d %s %s", out_dir, root .. "/src/*.java")
|
||||
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_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.open_float_terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
end
|
||||
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("LuaRun", M.run, {})
|
||||
|
||||
if M.keybinds.LuaRun then
|
||||
vim.keymap.set("n", M.keybinds.LuaRun, ":LuaRun<CR>", { silent = true })
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
||||
end
|
||||
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.open_float_terminal({ "lua " .. init_lua_path })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("python"), opts or {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("python"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("PythonPip", M.install_dependency, {})
|
||||
vim.api.nvim_create_user_command("PythonRun", M.run, {})
|
||||
for key, command in pairs(opts.keybinds) do
|
||||
if command == "PythonRun" then
|
||||
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
||||
end
|
||||
if command == "PythonPip" then
|
||||
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
local root = utils.get_project_root()
|
||||
@@ -18,49 +22,17 @@ function M.setup(opts)
|
||||
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("PythonPip", M.install_dependency, {})
|
||||
vim.api.nvim_create_user_command("PythonRun", M.run, {})
|
||||
|
||||
if M.keybinds.PythonRun then
|
||||
vim.keymap.set("n", M.keybinds.PythonRun, ":PythonRun<CR>", { silent = true })
|
||||
end
|
||||
if M.keybinds.PythonPip then
|
||||
vim.keymap.set("n", M.keybinds.PythonPip, ":PythonPip<CR>", { silent = true })
|
||||
end
|
||||
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)
|
||||
if not pip_module or pip_module == "" then return print("Pip canceled") end
|
||||
utils.open_float_terminal({ "pip install " .. pip_module })
|
||||
end)
|
||||
end
|
||||
|
||||
function M.run()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local main_file = root .. "/main.py"
|
||||
if vim.fn.filereadable(main_file) == 0 then
|
||||
return print("Error: main.py not found in project root.")
|
||||
end
|
||||
|
||||
-- Detect current shell
|
||||
local shell = vim.fn.getenv("SHELL") or ""
|
||||
local venv_cmd
|
||||
|
||||
if shell:match("fish") then
|
||||
local venv_fish = root .. "/venv/bin/activate.fish"
|
||||
venv_cmd = vim.fn.filereadable(venv_fish) == 1 and "source " .. venv_fish .. " && " or ""
|
||||
else
|
||||
local venv_bash = root .. "/venv/bin/activate"
|
||||
venv_cmd = vim.fn.filereadable(venv_bash) == 1 and "source " .. venv_bash .. " && " or ""
|
||||
end
|
||||
|
||||
utils.open_float_terminal(venv_cmd .. "python3 " .. main_file)
|
||||
utils.open_float_terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local M = {}
|
||||
|
||||
M.keybinds = {}
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("rust"), opts or {})
|
||||
for key, command in pairs(M.opts.keybinds) do
|
||||
M.keybinds[command] = key
|
||||
end
|
||||
|
||||
function M.setup(user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("rust"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("RustRun", M.run, {})
|
||||
|
||||
if M.keybinds.RustRun then
|
||||
vim.keymap.set("n", M.keybinds.RustRun, ":RustRun<CR>", { silent = true })
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,11 +13,10 @@ function M.run()
|
||||
local root = utils.get_project_root()
|
||||
if not root then return print("Error: Project root not found.") end
|
||||
|
||||
local cmd = "cargo build"
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
local cmd = { "cargo build" }
|
||||
local output = vim.fn.system(table.concat(cmd))
|
||||
|
||||
if not success then
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.open_float_terminal(cmd)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||
@@ -33,7 +24,7 @@ function M.run()
|
||||
)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||
else
|
||||
utils.open_float_terminal("cargo run")
|
||||
utils.open_float_terminal({ "cargo run" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user