feat(neotree): more sections with more info

This commit is contained in:
əlemi 2024-09-07 04:23:24 +02:00
parent 9eb057eeac
commit 3f4414dd25
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 61 additions and 14 deletions

View file

@ -65,6 +65,19 @@ local function new_workspace(name, owned, expanded)
}
end
---@param key string
---@param value string
---@return Item
local function new_entry(key, value)
return {
id = "codemp-entry-" .. key .. "-" .. value,
name = key .. ": " .. value,
type = "entry",
extra = {},
}
end
local function new_root(name)
return {
id = "codemp-tree-" .. name,
@ -75,6 +88,16 @@ local function new_root(name)
}
end
local function new_button(name)
return {
id = "codemp-button-" .. name,
name = name,
type = "button",
extra = {},
children = {}
}
end
---@return Item
local function spacer()
return {
@ -120,18 +143,23 @@ M.update_state = function(state)
table.insert(ws_section.children, new_workspace(ws.name, ws.owned))
end
table.insert(root, ws_section)
else
table.insert(root, spacer())
table.insert(root, new_root("[connect]"))
local status_section = new_root("client")
table.insert(status_section.children, new_entry("id", codemp.client.id))
table.insert(status_section.children, new_entry("name", codemp.client.username))
table.insert(root, status_section)
end
if codemp.client == nil then
table.insert(root, spacer())
table.insert(root, new_button("[connect]"))
end
renderer.show_nodes(root, state)
if codemp.workspace ~= nil then
for _, node in ipairs(state.tree:get_nodes()) do
node:expand()
end
end
end
return M

View file

@ -30,14 +30,25 @@ M.icon = function(config, node, state)
icon = "= "
highlight = highlights.DIRECTORY_ICON
elseif node.type == "root" then
if node:is_expanded() then
icon = "> "
else
icon = "- "
end
highlight = highlights.DIRECTORY_ICON
elseif node.type == "workspace" then
icon = "= "
highlight = highlights.SYMBOLIC_LINK_TARGET
icon = "* "
if node.extra.owned then
highlight = highlights.GIT_STAGED
else
highlight = highlights.DIRECTORY_ICON
end
elseif node.type == "user" then
icon = ":"
highlight = codemp_utils.color(node.name)
elseif node.type == "entry" then
icon = "$"
highlight = highlight.GIT_STAGED
end
return {
@ -50,12 +61,11 @@ M.name = function(config, node, state)
local highlight = config.highlight or highlights.FILE_NAME
local text = node.name
if node.type == "title" then
text = ":: " .. node.name .. " ::"
text = " :: " .. node.name .. " :: "
highlight = highlights.PREVIEW
elseif node.type == "root" then
elseif node.type == "root" or node.type == "button" then
text = " " .. node.name .. " "
highlight = highlights.FLOAT_TITLE
elseif node.type == "workspace" then
highlight = highlights.SYMBOLIC_LINK_TARGET
end
return {
text = text,

View file

@ -42,6 +42,15 @@ M.default_config = {
{ "spacer" },
{ "users" },
},
entry = {
{ "indent" },
{ "icon" },
{ "name" },
},
button = {
{ "indent" },
{ "name" },
},
},
}