-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcursor.lua
72 lines (57 loc) · 1.54 KB
/
cursor.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local api = vim.api
local util = require('satellite.util')
local HIGHLIGHT = 'SatelliteCursor'
--- @type Satellite.Handler
local handler = {
name = 'cursor',
}
--- @class Satellite.Handlers.CursorConfig: Satellite.Handlers.BaseConfig
--- @field symbols string[]
local config = {
enable = true,
overlap = true,
priority = 100,
symbols = { '⎺', '⎻', '⎼', '⎽' },
}
local function setup_hl()
api.nvim_set_hl(0, HIGHLIGHT, {
default = true,
fg = api.nvim_get_hl(0, { name = 'NonText' }).fg,
})
end
--- @param user_config Satellite.Handlers.CursorConfig
--- @param update fun()
function handler.setup(user_config, update)
config = vim.tbl_deep_extend('force', config, user_config)
handler.config = config
local group = api.nvim_create_augroup('satellite_cursor', {})
api.nvim_create_autocmd('ColorScheme', {
group = group,
callback = setup_hl,
})
setup_hl()
api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
group = group,
callback = update,
})
end
--- @param symbols string[]
--- @param f number
--- @return string
local function get_symbol(symbols, f)
local total = #symbols
local index = math.max(1, util.round((0.5 - f) * total))
return symbols[index] or tostring(index)
end
function handler.update(_, winid)
local cursor = api.nvim_win_get_cursor(winid)
local pos, f = util.row_to_barpos(winid, cursor[1] - 1)
return {
{
pos = pos,
highlight = HIGHLIGHT,
symbol = get_symbol(config.symbols, f),
},
}
end
require('satellite.handlers').register(handler)