rework: check description

docs: removed lines about plenary
removal: plenary
chore: optmized presets load to default nil as 'max'
rework: changed window format of manager and added coloring

Future plans: Add custom highlight-groups for Polydev to configure
border and background or manager
This commit is contained in:
DarthMooMancer
2025-05-15 01:00:57 -04:00
parent 9105add777
commit 28fdb698bf
6 changed files with 97 additions and 64 deletions
+1
View File
@@ -10,6 +10,7 @@ function M.setup(opts)
end
vim.api.nvim_create_user_command("PolydevOpen", function() ui.manager(config.get("globals").project_root) end, {})
-- require("Polydev.styles").setup_highlights()
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
for key, _ in pairs(keys) do
+1 -8
View File
@@ -29,14 +29,7 @@ local presets = {
---@param preset string
---@return table|nil
function M.getPresets(preset)
if presets[preset] ~= nil then
return presets[preset]
elseif presets[preset] == nil then
return nil
else
print("Preset option: " .. preset .. " does not exist")
end
return {}
return presets[preset]
end
return M
+23
View File
@@ -0,0 +1,23 @@
local M = {}
function M.setup_highlights()
-- Only set if not already defined by colorscheme
local function define(name, opts)
if vim.fn.hlexists(name) == 0 then
vim.api.nvim_set_hl(0, name, opts)
end
end
define("PolydevNormal", {
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).foreground,
bg = vim.api.nvim_get_hl_by_name("Normal", true).background
})
define("PolydevBorder", {
fg = vim.api.nvim_get_hl_by_name("Function", true).foreground,
bg = vim.api.nvim_get_hl_by_name("Normal", true).background
})
define("PolydevTitle", { fg = "#89dceb", bold = true })
end
return M
+4 -4
View File
@@ -2,7 +2,7 @@ local utils = require("Polydev.utils")
local M = {}
local function aux_file(guard, file_type, file_name)
local function extras(guard, file_type, file_name)
if not file_name then return print("Header file creation canceled") end
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
local content = string.format([[
@@ -239,14 +239,14 @@ public class %s {
}
}
M.aux_files = {
M.extras = {
run = function (lang, file_name)
if lang == "c" then
aux_file("_H", ".h", file_name)
extras("_H", ".h", file_name)
print("Successful creation of " .. file_name .. ".h")
end
if lang == "cpp" then
aux_file("_HPP", ".hpp", file_name)
extras("_HPP", ".hpp", file_name)
print("Successful creation of " .. file_name .. ".hpp")
end
end
+65 -46
View File
@@ -39,6 +39,9 @@ local function get_entries(path)
return result
end
---@param list table
---@param query string
---@return table
local function fuzzy_filter(list, query)
local result = {}
query = query:lower()
@@ -51,6 +54,10 @@ local function fuzzy_filter(list, query)
end
local loaded_languages = {}
---@param lang string
---@param opts? table
---@return boolean
function M.load_language_module(lang, opts)
if loaded_languages[lang] then return true end
@@ -67,53 +74,64 @@ function M.manager(project_root)
local Popup = require("nui.popup")
local Layout = require("nui.layout")
local event = require("nui.utils.autocmd").event
local Path = require("plenary.path")
local display_dir = vim.fn.expand(vim.fn.getcwd())
local cwd = display_dir
local entries = get_entries(cwd)
local current_view = vim.deepcopy(entries)
-- Create a new custom highlight group with Normal background and NormalFloat foreground
vim.api.nvim_set_hl(0, "CustomFloatText", {
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).foreground,
bg = vim.api.nvim_get_hl_by_name("Normal", true).background,
})
local popup, search, preview = Popup({
enter = true,
focusable = true,
border = {
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
text = { top = " Project Manager ", top_align = "center" },
highlight = "Normal",
text = { top = " Results ", top_align = "center" },
},
position = "50%",
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
}
}), Popup({
enter = false,
focusable = true,
border = {
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
text = { top = " Search ", top_align = "center" },
highlight = "Normal",
style = "rounded", -- "rounded", "single" or "solid".
text = { top = " Find Files ", top_align = "center" },
},
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
}
}), Popup({
enter = false,
focusable = false,
border = {
style = "rounded",
text = { top = " Preview ", top_align = "center" },
highlight = "Normal",
text = { top = " Grep Preview ", top_align = "center" },
},
position = "50%",
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
}
})
local layout = Layout({
position = "50%",
size = { width = "70%", height = "70%" },
position = "55%",
size = { width = "81%", height = "90%" },
},
Layout.Box({
Layout.Box(search, { size = "10%" }),
Layout.Box({
Layout.Box(popup, { size = "50%" }),
Layout.Box(preview, { size = "50%" }),
}, { dir = "row", size = "90%" }),
}, { dir = "col" })
Layout.Box(search, { size = "10%" }),
Layout.Box(popup, { size = "93%" }),
}, { dir = "col", size = "48%" }),
Layout.Box(preview, { size = "51.5%" }),
}, { dir = "row" })
)
layout:mount()
@@ -180,7 +198,7 @@ function M.manager(project_root)
table.insert(entries, 1, {
name = "../",
type = "directory",
full_path = Path:new(cwd):parent():absolute(),
full_path = vim.fn.fnamemodify(cwd, ":h"),
is_up = true
})
end
@@ -234,32 +252,7 @@ function M.manager(project_root)
-- Mappings
popup:map("n", "q", function() popup:unmount() end)
-- Creates a new folder
popup:map("n", "a", function()
vim.ui.input({ prompt = "New folder name:" }, function(input)
if input then
vim.fn.mkdir(cwd .. "/" .. input, "p")
refresh()
render()
end
end)
end)
-- Deletes Folder and confirms deletion
popup:map("n", "D", function()
local entry = get_selected_entry()
if not entry.is_up then
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
if input == "y" or input == "Y" then
vim.fn.delete(entry.full_path, "rf")
refresh()
render()
end
end)
end
end)
-- Creates a new file in project
-- Creates new file
popup:map("n", "%", function()
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
if not lang or lang == "" then return print("File creation canceled") end
@@ -277,15 +270,16 @@ function M.manager(project_root)
end)
end)
-- Creates extra file
popup:map("n", "x", function()
vim.ui.input({ prompt = "Enter language for new auxilary file: "}, function(lang)
if not lang or lang == "" then return print("File create canceled") end
if M.load_language_module(lang) and templates.aux_files.run then
if M.load_language_module(lang) and templates.extras.run then
popup:unmount()
vim.schedule(function()
vim.ui.input({ prompt = "Enter file name: "}, function(file_name)
if not file_name or file_name == "" then return print("File creation canceled") end
templates.aux_files.run(lang, file_name)
templates.extras.run(lang, file_name)
end)
end)
else
@@ -294,7 +288,18 @@ function M.manager(project_root)
end)
end)
-- Creates a new project
-- Creates a new folder
popup:map("n", "a", function()
vim.ui.input({ prompt = "New folder name:" }, function(input)
if input then
vim.fn.mkdir(cwd .. "/" .. input, "p")
refresh()
render()
end
end)
end)
-- Creates new project
popup:map("n", "d", function()
local opts = {}
vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
@@ -314,6 +319,20 @@ function M.manager(project_root)
end)
end)
-- Deletes Folder and confirms deletion
popup:map("n", "D", function()
local entry = get_selected_entry()
if not entry.is_up then
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
if input == "y" or input == "Y" then
vim.fn.delete(entry.full_path, "rf")
refresh()
render()
end
end)
end
end)
-- Renames Files and Folders
popup:map("n", "R", function()
local entry = get_selected_entry()
@@ -347,7 +366,7 @@ function M.manager(project_root)
end)
popup:map("n", "<BS>", function()
local parent = Path:new(cwd):parent():absolute()
local parent = vim.fn.fnamemodify(cwd, ":h")
if parent ~= cwd then
cwd = parent
refresh()