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 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) local function new_root(name)
return { return {
id = "codemp-tree-" .. name, id = "codemp-tree-" .. name,
@ -75,6 +88,16 @@ local function new_root(name)
} }
end end
local function new_button(name)
return {
id = "codemp-button-" .. name,
name = name,
type = "button",
extra = {},
children = {}
}
end
---@return Item ---@return Item
local function spacer() local function spacer()
return { return {
@ -120,18 +143,23 @@ M.update_state = function(state)
table.insert(ws_section.children, new_workspace(ws.name, ws.owned)) table.insert(ws_section.children, new_workspace(ws.name, ws.owned))
end end
table.insert(root, ws_section) table.insert(root, ws_section)
else
table.insert(root, spacer()) 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 end
renderer.show_nodes(root, state) renderer.show_nodes(root, state)
if codemp.workspace ~= nil then
for _, node in ipairs(state.tree:get_nodes()) do for _, node in ipairs(state.tree:get_nodes()) do
node:expand() node:expand()
end end
end
end end
return M return M

View file

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

View file

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