-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathdisplay_duration.lua
54 lines (51 loc) · 1.36 KB
/
display_duration.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
local task_list = require("overseer.task_list")
local util = require("overseer.util")
local timer
---@type overseer.ComponentFileDefinition
local comp = {
desc = "Display the run duration",
params = {
detail_level = {
desc = "Show the duration at this detail level",
type = "integer",
default = 1,
validate = function(v)
return v >= 1 and v <= 3
end,
},
},
constructor = function(params)
return {
duration = nil,
start_time = nil,
on_reset = function(self, task)
self.duration = nil
self.start_time = nil
end,
on_start = function(self)
if not timer then
timer = assert(vim.loop.new_timer())
timer:start(
1000,
1000,
vim.schedule_wrap(function()
task_list.rerender()
end)
)
end
self.start_time = os.time()
end,
on_complete = function(self)
self.duration = os.time() - self.start_time
end,
render = function(self, task, lines, highlights, detail)
if detail < params.detail_level or (not self.duration and not self.start_time) then
return
end
local duration = self.duration or os.time() - self.start_time
table.insert(lines, util.format_duration(duration))
end,
}
end,
}
return comp