From 3f4414dd2591ce996696bf7e903c71fd0f4141a3 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 7 Sep 2024 04:23:24 +0200 Subject: [PATCH] feat(neotree): more sections with more info --- lua/codemp/neo-tree/bridge.lua | 42 +++++++++++++++++++++++++----- lua/codemp/neo-tree/components.lua | 24 ++++++++++++----- lua/codemp/neo-tree/init.lua | 9 +++++++ 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/lua/codemp/neo-tree/bridge.lua b/lua/codemp/neo-tree/bridge.lua index 9ea1229..ddc3138 100644 --- a/lua/codemp/neo-tree/bridge.lua +++ b/lua/codemp/neo-tree/bridge.lua @@ -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,17 +143,22 @@ 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 + for _, node in ipairs(state.tree:get_nodes()) do + node:expand() end end diff --git a/lua/codemp/neo-tree/components.lua b/lua/codemp/neo-tree/components.lua index 1755d13..fee2cc0 100644 --- a/lua/codemp/neo-tree/components.lua +++ b/lua/codemp/neo-tree/components.lua @@ -30,14 +30,25 @@ M.icon = function(config, node, state) icon = "= " highlight = highlights.DIRECTORY_ICON elseif node.type == "root" then - icon = "> " + 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, diff --git a/lua/codemp/neo-tree/init.lua b/lua/codemp/neo-tree/init.lua index 4ecf0fe..41f0b45 100644 --- a/lua/codemp/neo-tree/init.lua +++ b/lua/codemp/neo-tree/init.lua @@ -42,6 +42,15 @@ M.default_config = { { "spacer" }, { "users" }, }, + entry = { + { "indent" }, + { "icon" }, + { "name" }, + }, + button = { + { "indent" }, + { "name" }, + }, }, }