This repository was archived by the owner on Apr 20, 2026. It is now read-only.
forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinner.lua
More file actions
84 lines (72 loc) · 1.61 KB
/
Copy pathspinner.lua
File metadata and controls
84 lines (72 loc) · 1.61 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
---@class CopilotChat.Spinner
---@field bufnr number
---@field set fun(self: CopilotChat.Spinner, text: string, virt_line: boolean)
---@field start fun(self: CopilotChat.Spinner)
---@field finish fun(self: CopilotChat.Spinner)
local utils = require('CopilotChat.utils')
local class = utils.class
local spinner_frames = {
'⠋',
'⠙',
'⠹',
'⠸',
'⠼',
'⠴',
'⠦',
'⠧',
'⠇',
'⠏',
}
local Spinner = class(function(self, bufnr, ns, title)
self.ns = ns
self.bufnr = bufnr
self.title = title
self.timer = nil
self.index = 1
end)
function Spinner:start()
if self.timer then
return
end
self.timer = vim.loop.new_timer()
self.timer:start(
0,
100,
vim.schedule_wrap(function()
if
not vim.api.nvim_buf_is_valid(self.bufnr)
or not vim.api.nvim_buf_is_loaded(self.bufnr)
or not self.timer
then
self:finish()
return
end
vim.api.nvim_buf_set_extmark(
self.bufnr,
self.ns,
math.max(0, vim.api.nvim_buf_line_count(self.bufnr) - 1),
0,
{
id = self.ns,
hl_mode = 'combine',
priority = 100,
virt_text = vim.tbl_map(function(t)
return { t, 'CursorColumn' }
end, vim.split(spinner_frames[self.index], '\n')),
}
)
self.index = self.index % #spinner_frames + 1
end)
)
end
function Spinner:finish()
if not self.timer then
return
end
local timer = self.timer
self.timer = nil
timer:stop()
timer:close()
vim.api.nvim_buf_del_extmark(self.bufnr, self.ns, self.ns)
end
return Spinner