Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 13:04:48 -04:00
parent 8fe0129593
commit 16d4fe60ab
+26 -20
View File
@@ -4,7 +4,6 @@ M.c_build = nil
M.c_run = nil M.c_run = nil
M.new_c_file = nil M.new_c_file = nil
M.new_c_project = nil M.new_c_project = nil
M.project_name = nil
-- Default config -- Default config
M.config = { M.config = {
@@ -133,7 +132,6 @@ function M.create_project()
end end
-- Paths for the project -- Paths for the project
M.project_name = project_name
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
local src_dir = project_root .. "/src" local src_dir = project_root .. "/src"
local build_dir = project_root .. "/build" local build_dir = project_root .. "/build"
@@ -232,29 +230,37 @@ function M.build()
-- local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir .. -- local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir ..
-- " && mv " .. legacy_out_dir .. "/* " .. build_dir .. -- " && mv " .. legacy_out_dir .. "/* " .. build_dir ..
-- " && rm -rd " .. project_root .. "/" .. "root/" -- " && rm -rd " .. project_root .. "/" .. "root/"
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. M.project_name
local into_build = "cd " .. project_root .. "/build"
local into_build_status = vim.fn.system(into_build)
if vim.v.shell_error ~= 0 then
print("Could not go into build dir:\n" .. into_build_status)
end
local project_root_build = current_dir:match("(.*)/build") vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_root_build then if not project_name or project_name == "" then
print("Error: Must be inside the 'build' directory.") print("Project creation canceled.")
return return
end end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
local into_build = "cd " .. project_root .. "/build"
local into_build_status = vim.fn.system(into_build)
if vim.v.shell_error ~= 0 then
print("Could not go into build dir:\n" .. into_build_status)
end
local compile_command = "cmake .. && make" local project_root_build = current_dir:match("(.*)/build")
local compile_status = vim.fn.system(compile_command) if not project_root_build then
print("Error: Must be inside the 'build' directory.")
return
end
if vim.v.shell_error ~= 0 then local compile_command = "cmake .. && make"
print("Error during compilation:\n" .. compile_status) local compile_status = vim.fn.system(compile_command)
else
print("Compilation successful!") if vim.v.shell_error ~= 0 then
end print("Error during compilation:\n" .. compile_status)
else
print("Compilation successful!")
end
end)
end end
-- Run Java program in floating terminal -- Run Java program in floating terminal
function M.run() function M.run()
local current_dir = vim.fn.expand("%:p:h") local current_dir = vim.fn.expand("%:p:h")