diff --git a/src/utils.lua b/src/utils.lua index 0254f52..94f7f0e 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -1,5 +1,19 @@ local native = require('codemp.loader').load() +local available_colors = { -- TODO these are definitely not portable! + "ErrorMsg", + "WarningMsg", + "MatchParen", + "SpecialMode", + "CmpItemKindFunction", + "CmpItemKindValue", + "CmpItemKindInterface", +} + +local function color(x) + return available_colors[ (native.hash(x) % #available_colors) + 1 ] +end + local function order_tuples(x) -- TODO send help... if x[1][1] < x[2][1] then return { { x[1][1], x[1][2] }, { x[2][1], x[2][2] } } @@ -149,4 +163,6 @@ return { replace_content = buffer_replace_content, }, hash = native.hash, + available_colors = available_colors, + color = color, } diff --git a/src/workspace.lua b/src/workspace.lua index e4a3529..6630f88 100644 --- a/src/workspace.lua +++ b/src/workspace.lua @@ -7,15 +7,6 @@ local window = require('codemp.window') local user_hl = {} local tree_buf = nil -local available_colors = { -- TODO these are definitely not portable! - "ErrorMsg", - "WarningMsg", - "MatchParen", - "SpecialMode", - "CmpItemKindFunction", - "CmpItemKindValue", - "CmpItemKindInterface", -} local function register_cursor_callback(controller) vim.api.nvim_create_autocmd({"CursorMoved", "CursorMovedI", "ModeChanged"}, { @@ -38,7 +29,7 @@ local function register_cursor_handler(controller) if user_hl[event.user] == nil then user_hl[event.user] = { ns = vim.api.nvim_create_namespace("codemp-cursor-" .. event.user), - hi = available_colors[ math.random( #available_colors ) ], + hi = utils.color(event.user), } end local old_buffer = buffers.users[event.user]