diff --git a/lua/codemp/buffers.lua b/lua/codemp/buffers.lua index 9e0c6c6..bfb985b 100644 --- a/lua/codemp/buffers.lua +++ b/lua/codemp/buffers.lua @@ -97,7 +97,7 @@ local function attach(name, buffer, content, nowait) end utils.buffer.set_content(buffer, event.content, event.start, event.finish) if event.hash ~= nil then - if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then + if CODEMP.native.hash(utils.buffer.get_content(buffer)) ~= event.hash then -- OUT OF SYNC! -- TODO this may be destructive! we should probably prompt the user before doing this print(" /!\\ out of sync, resynching...") diff --git a/lua/codemp/init.lua b/lua/codemp/init.lua index 0d1256d..1496212 100644 --- a/lua/codemp/init.lua +++ b/lua/codemp/init.lua @@ -56,6 +56,7 @@ if CODEMP == nil then end) require('codemp.command') -- not really related but should only happen once + require('codemp.utils').setup_colors() -- create highlight groups for users end } end diff --git a/lua/codemp/neo-tree/components.lua b/lua/codemp/neo-tree/components.lua index b6d5bd6..5a754f7 100644 --- a/lua/codemp/neo-tree/components.lua +++ b/lua/codemp/neo-tree/components.lua @@ -47,7 +47,7 @@ M.icon = function(config, node, state) end elseif node.type == "user" then icon = ":" - highlight = codemp_utils.color(node.name) + highlight = codemp_utils.color(node.name).bg elseif node.type == "entry" then icon = "$" highlight = highlights.GIT_STAGED @@ -94,7 +94,7 @@ M.users = function(config, node, state) if buf == node.name then table.insert(out, { text = " ", - highlight = codemp_utils.color(user), + highlight = codemp_utils.color(user).bg, align = "end", }) end diff --git a/lua/codemp/utils.lua b/lua/codemp/utils.lua index c628c0f..e40c107 100644 --- a/lua/codemp/utils.lua +++ b/lua/codemp/utils.lua @@ -1,19 +1,32 @@ -local native = require('codemp.loader').load() - -local available_colors = { -- TODO these are definitely not portable! - "ErrorMsg", - "WarningMsg", - "MatchParen", - "SpecialMode", - "CmpItemKindFunction", - "CmpItemKindValue", - "CmpItemKindInterface", +local colors = { + { "#AC7EA8", 175 }, + { "#81A1C1", 74 }, + { "#EBCB8B", 222 }, + { "#2E8757", 72 }, + { "#BF616A", 167 }, + { "#8F81D4", 98 }, + { "#D69C63", 179 }, } ----@param x string ----@return string -local function color(x) - return available_colors[ math.fmod(math.abs(native.hash(x)), #available_colors) + 1 ] +local function setup_colors() + for n, color in ipairs(colors) do + vim.api.nvim_set_hl(0, string.format("CodempUser#%s", n), { fg = color[1], bg = nil, ctermfg = color[2], ctermbg = 0 }) + vim.api.nvim_set_hl(0, string.format("CodempUserInverted#%s", n), { fg = "#201F29", bg = color[1], ctermfg = 234, ctermbg = color[2] }) + end +end + +---@class HighlightPair +---@field fg string +---@field bg string + +---@param name string +---@return HighlightPair +local function color(name) + local index = math.fmod(math.abs(CODEMP.native.hash(name)), #colors) + 1 + return { + fg = "CodempUser#" .. index, + bg = "CodempUserInverted#" .. index, + } end local function async_poller(generator, callback) @@ -183,9 +196,6 @@ local function separator() end end -local hash_fn = nil -if native ~= nil then hash_fn = native.hash end - return { cursor = { position = cursor_position, @@ -195,9 +205,9 @@ return { get_content = buffer_get_content, set_content = buffer_set_content, }, - hash = hash_fn, available_colors = available_colors, color = color, poller = async_poller, sep = separator, + setup_colors = setup_colors, } diff --git a/lua/codemp/window.lua b/lua/codemp/window.lua index f9e3ebe..adb5dd5 100644 --- a/lua/codemp/window.lua +++ b/lua/codemp/window.lua @@ -77,11 +77,11 @@ local function update_window() if off[row] == nil then off[row] = 0 end - vim.highlight.range(buffer_id, ns, utils.color(user), {row-1,4+off[row]}, {row-1, 5+off[row]}) + vim.highlight.range(buffer_id, ns, utils.color(user).bg, {row-1,4+off[row]}, {row-1, 5+off[row]}) off[row] = off[row] + 1 row = user_to_row[user] vim.highlight.range(buffer_id, ns, 'InlayHint', {row-1, 0}, {row-1, 1}) - vim.highlight.range(buffer_id, ns, utils.color(user), {row-1, 2}, {row-1, 3}) + vim.highlight.range(buffer_id, ns, utils.color(user).bg, {row-1, 2}, {row-1, 3}) end vim.api.nvim_set_option_value('modifiable', false, { buf = buffer_id }) end diff --git a/lua/codemp/workspace.lua b/lua/codemp/workspace.lua index 0a76d04..8f7a885 100644 --- a/lua/codemp/workspace.lua +++ b/lua/codemp/workspace.lua @@ -3,7 +3,7 @@ local buffers = require('codemp.buffers') ---@class UserHighlight ---@field ns integer namespace to use for this user ----@field hi string color for user to use +---@field hi HighlightPair color for user to use ---@field pos [integer, integer] cursor start position of this user ---@type table @@ -94,23 +94,18 @@ local function register_cursor_handler(ws) event.start[1], event.start[2], { - end_col = event.finish[1], - end_row = event.finish[2], - hl_group = user_hl[event.user].hi, - hl_eol = true, - virt_text_pos = "overlay", + end_row = event.finish[1], + end_col = event.finish[2], + hl_group = user_hl[event.user].hi.bg, + virt_text_pos = "right_align", + sign_text = string.sub(event.user, 0, 1), + sign_hl_group = user_hl[event.user].hi.fg, + strict = false, virt_text = { - { event.user, "InlayHint" } + { event.user, user_hl[event.user].hi.fg } }, } ) - utils.multiline_highlight( - buffer_id, - user_hl[event.user].ns, - user_hl[event.user].hi, - event.start, - event.finish - ) end if old_buffer ~= event.buffer then require('codemp.window').update() -- redraw user positions @@ -170,4 +165,5 @@ return { leave = leave, map = user_hl, list = fetch_workspaces_list, + setup_colors = setup_colors, }