mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-25 00:44:52 +01:00
feat: reworked colors, improved cursor marker
This commit is contained in:
parent
d991a81601
commit
52d356ea02
6 changed files with 44 additions and 37 deletions
|
@ -97,7 +97,7 @@ local function attach(name, buffer, content, nowait)
|
||||||
end
|
end
|
||||||
utils.buffer.set_content(buffer, event.content, event.start, event.finish)
|
utils.buffer.set_content(buffer, event.content, event.start, event.finish)
|
||||||
if event.hash ~= nil then
|
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!
|
-- OUT OF SYNC!
|
||||||
-- TODO this may be destructive! we should probably prompt the user before doing this
|
-- TODO this may be destructive! we should probably prompt the user before doing this
|
||||||
print(" /!\\ out of sync, resynching...")
|
print(" /!\\ out of sync, resynching...")
|
||||||
|
|
|
@ -56,6 +56,7 @@ if CODEMP == nil then
|
||||||
end)
|
end)
|
||||||
|
|
||||||
require('codemp.command') -- not really related but should only happen once
|
require('codemp.command') -- not really related but should only happen once
|
||||||
|
require('codemp.utils').setup_colors() -- create highlight groups for users
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ M.icon = function(config, node, state)
|
||||||
end
|
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).bg
|
||||||
elseif node.type == "entry" then
|
elseif node.type == "entry" then
|
||||||
icon = "$"
|
icon = "$"
|
||||||
highlight = highlights.GIT_STAGED
|
highlight = highlights.GIT_STAGED
|
||||||
|
@ -94,7 +94,7 @@ M.users = function(config, node, state)
|
||||||
if buf == node.name then
|
if buf == node.name then
|
||||||
table.insert(out, {
|
table.insert(out, {
|
||||||
text = " ",
|
text = " ",
|
||||||
highlight = codemp_utils.color(user),
|
highlight = codemp_utils.color(user).bg,
|
||||||
align = "end",
|
align = "end",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,32 @@
|
||||||
local native = require('codemp.loader').load()
|
local colors = {
|
||||||
|
{ "#AC7EA8", 175 },
|
||||||
local available_colors = { -- TODO these are definitely not portable!
|
{ "#81A1C1", 74 },
|
||||||
"ErrorMsg",
|
{ "#EBCB8B", 222 },
|
||||||
"WarningMsg",
|
{ "#2E8757", 72 },
|
||||||
"MatchParen",
|
{ "#BF616A", 167 },
|
||||||
"SpecialMode",
|
{ "#8F81D4", 98 },
|
||||||
"CmpItemKindFunction",
|
{ "#D69C63", 179 },
|
||||||
"CmpItemKindValue",
|
|
||||||
"CmpItemKindInterface",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param x string
|
local function setup_colors()
|
||||||
---@return string
|
for n, color in ipairs(colors) do
|
||||||
local function color(x)
|
vim.api.nvim_set_hl(0, string.format("CodempUser#%s", n), { fg = color[1], bg = nil, ctermfg = color[2], ctermbg = 0 })
|
||||||
return available_colors[ math.fmod(math.abs(native.hash(x)), #available_colors) + 1 ]
|
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
|
end
|
||||||
|
|
||||||
local function async_poller(generator, callback)
|
local function async_poller(generator, callback)
|
||||||
|
@ -183,9 +196,6 @@ local function separator()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local hash_fn = nil
|
|
||||||
if native ~= nil then hash_fn = native.hash end
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cursor = {
|
cursor = {
|
||||||
position = cursor_position,
|
position = cursor_position,
|
||||||
|
@ -195,9 +205,9 @@ return {
|
||||||
get_content = buffer_get_content,
|
get_content = buffer_get_content,
|
||||||
set_content = buffer_set_content,
|
set_content = buffer_set_content,
|
||||||
},
|
},
|
||||||
hash = hash_fn,
|
|
||||||
available_colors = available_colors,
|
available_colors = available_colors,
|
||||||
color = color,
|
color = color,
|
||||||
poller = async_poller,
|
poller = async_poller,
|
||||||
sep = separator,
|
sep = separator,
|
||||||
|
setup_colors = setup_colors,
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,11 +77,11 @@ local function update_window()
|
||||||
if off[row] == nil then
|
if off[row] == nil then
|
||||||
off[row] = 0
|
off[row] = 0
|
||||||
end
|
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
|
off[row] = off[row] + 1
|
||||||
row = user_to_row[user]
|
row = user_to_row[user]
|
||||||
vim.highlight.range(buffer_id, ns, 'InlayHint', {row-1, 0}, {row-1, 1})
|
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
|
end
|
||||||
vim.api.nvim_set_option_value('modifiable', false, { buf = buffer_id })
|
vim.api.nvim_set_option_value('modifiable', false, { buf = buffer_id })
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ local buffers = require('codemp.buffers')
|
||||||
|
|
||||||
---@class UserHighlight
|
---@class UserHighlight
|
||||||
---@field ns integer namespace to use for this user
|
---@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
|
---@field pos [integer, integer] cursor start position of this user
|
||||||
|
|
||||||
---@type table<string, UserHighlight>
|
---@type table<string, UserHighlight>
|
||||||
|
@ -94,23 +94,18 @@ local function register_cursor_handler(ws)
|
||||||
event.start[1],
|
event.start[1],
|
||||||
event.start[2],
|
event.start[2],
|
||||||
{
|
{
|
||||||
end_col = event.finish[1],
|
end_row = event.finish[1],
|
||||||
end_row = event.finish[2],
|
end_col = event.finish[2],
|
||||||
hl_group = user_hl[event.user].hi,
|
hl_group = user_hl[event.user].hi.bg,
|
||||||
hl_eol = true,
|
virt_text_pos = "right_align",
|
||||||
virt_text_pos = "overlay",
|
sign_text = string.sub(event.user, 0, 1),
|
||||||
|
sign_hl_group = user_hl[event.user].hi.fg,
|
||||||
|
strict = false,
|
||||||
virt_text = {
|
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
|
end
|
||||||
if old_buffer ~= event.buffer then
|
if old_buffer ~= event.buffer then
|
||||||
require('codemp.window').update() -- redraw user positions
|
require('codemp.window').update() -- redraw user positions
|
||||||
|
@ -170,4 +165,5 @@ return {
|
||||||
leave = leave,
|
leave = leave,
|
||||||
map = user_hl,
|
map = user_hl,
|
||||||
list = fetch_workspaces_list,
|
list = fetch_workspaces_list,
|
||||||
|
setup_colors = setup_colors,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue