refactor: fixed deprecated write_file to use table instead of string for

each language in templates.projects
This commit is contained in:
DarthMooMancer
2025-05-12 00:41:05 -04:00
parent 677e5bbc67
commit 4ecaf54f82
7 changed files with 103 additions and 106 deletions
-25
View File
@@ -10,15 +10,11 @@ function M.setup(opts)
M.keybinds[command] = key
end
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
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 })
end
if M.keybinds.NewCHeaderFile then
vim.keymap.set("n", M.keybinds.NewCHeaderFile, ":NewCHeaderFile<CR>", { silent = true })
end
end
function M.get_project_root()
@@ -31,27 +27,6 @@ function M.get_project_root()
end
end
function M.create_new_header_file()
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
if not header_name then return print("Header file creation canceled.") end
local root_dir = M.get_project_root()
if not root_dir then return print("Error: Project root not found.") end
local guard_macro = header_name:upper():gsub("[^A-Z0-9]", "_") .. "_H"
local content = string.format([[
#ifndef %s
#define %s
#include <stdio.h>
// Function prototypes
void example_function();
#endif // %s
]], guard_macro, guard_macro, guard_macro)
utils.write_file(root_dir .. "/include/" .. header_name .. ".h", content)
end)
end
function M.run()
local root = M.get_project_root()
if not root then return print("Error: Project root not found.") end