major changes to try and fix a bunch of random bugs
This commit is contained in:
+39
-45
@@ -26,9 +26,8 @@ end
|
||||
---@param project_root string
|
||||
function M.manager(project_root)
|
||||
local templates = require("Polydev.templates")
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
local width, height = math.floor(ui.width * 0.40), math.floor(ui.height * 0.4)
|
||||
local row, col = math.floor((ui.height - height) / 3), math.floor((ui.width - width) / 2)
|
||||
local width, height = math.floor(vim.o.columns * 0.40), math.floor(vim.o.lines * 0.4)
|
||||
local row, col = math.floor((vim.o.lines - height) / 3), math.floor((vim.o.columns - width) / 2)
|
||||
local content_row = row + 2
|
||||
local content_height = height - 3
|
||||
|
||||
@@ -53,8 +52,11 @@ function M.manager(project_root)
|
||||
end
|
||||
|
||||
local function update_screen()
|
||||
local entries = get_entries(cwd)
|
||||
local root = vim.fn.expand(project_root)
|
||||
if vim.fn.isdirectory(root) == 0 then
|
||||
vim.fn.mkdir(root, "p")
|
||||
end
|
||||
local entries = get_entries(cwd)
|
||||
if not cwd:find(root, 1, true) then
|
||||
cwd = root
|
||||
entries = get_entries(cwd)
|
||||
@@ -70,8 +72,13 @@ function M.manager(project_root)
|
||||
current_view = vim.deepcopy(entries)
|
||||
|
||||
local lines = {}
|
||||
for i, item in ipairs(current_view) do
|
||||
table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
|
||||
if #current_view == 0 then
|
||||
table.insert(lines, "No projects found in " .. cwd)
|
||||
table.insert(lines, "Press d to create a project, or a to add a folder.")
|
||||
else
|
||||
for i, item in ipairs(current_view) do
|
||||
table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
|
||||
end
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(content_buf, 0, -1, false, lines)
|
||||
end
|
||||
@@ -84,18 +91,15 @@ function M.manager(project_root)
|
||||
end
|
||||
|
||||
---@param type string
|
||||
---@return string, string
|
||||
local function get_inputs(type)
|
||||
local l, n
|
||||
---@param callback fun(lang: string, name: string)
|
||||
local function get_inputs(type, callback)
|
||||
vim.ui.input({ prompt = "Enter language for new " .. type .. ": " }, function(lang)
|
||||
if lang == nil then return end
|
||||
vim.ui.input({ prompt = "Enter ".. type .. " name: " }, function(name)
|
||||
if not lang or lang == "" then return end
|
||||
if not lang or lang == "" then return end
|
||||
vim.ui.input({ prompt = "Enter " .. type .. " name: " }, function(name)
|
||||
if not name or name == "" then return end
|
||||
l, n = lang, name
|
||||
callback(lang, name)
|
||||
end)
|
||||
end)
|
||||
return l, n
|
||||
end
|
||||
|
||||
update_screen()
|
||||
@@ -138,42 +142,32 @@ function M.manager(project_root)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "%", function()
|
||||
local lang, name = get_inputs("file")
|
||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||
if templates.files[lang].run then
|
||||
if name ~= nil and name ~= "" then
|
||||
close_all_windows()
|
||||
templates.files[lang].run(name)
|
||||
get_inputs("file", function(lang, name)
|
||||
local file = templates.files[lang]
|
||||
if not file or not file.run then
|
||||
return print("Error: No file creation method for " .. lang)
|
||||
end
|
||||
else
|
||||
print("Error: No File creation method for " .. lang)
|
||||
end
|
||||
close_all_windows()
|
||||
file.run(name)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "x", function()
|
||||
local lang, name = get_inputs("aux file")
|
||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||
if templates.extras.run then
|
||||
if name ~= nil and name ~= "" then
|
||||
close_all_windows()
|
||||
templates.extras.run(lang, name)
|
||||
end
|
||||
else
|
||||
print("Error: No File creation method for " .. lang)
|
||||
end
|
||||
get_inputs("aux file", function(lang, name)
|
||||
close_all_windows()
|
||||
templates.extras.run(lang, name)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "d", function ()
|
||||
local lang, name = get_inputs("project")
|
||||
local opts = {}
|
||||
opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get(lang), opts or {})
|
||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||
if templates.projects[lang].run then
|
||||
if name ~= nil and name ~= "" then
|
||||
close_all_windows()
|
||||
templates.projects[lang].run(name, opts.project_root)
|
||||
vim.keymap.set("n", "d", function()
|
||||
get_inputs("project", function(lang, name)
|
||||
local project = templates.projects[lang]
|
||||
if not project or not project.run then
|
||||
return print("Error: No project creation method for " .. lang)
|
||||
end
|
||||
else
|
||||
print("Error: No project creation method for " .. lang)
|
||||
end
|
||||
local opts = require("Polydev.configs").get(lang)
|
||||
local run_root = opts.project_root or project_root
|
||||
close_all_windows()
|
||||
project.run(name, run_root)
|
||||
end)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "<CR>", function()
|
||||
local entry = get_selected_entry()
|
||||
|
||||
Reference in New Issue
Block a user