-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathon_output_summarize.lua
60 lines (58 loc) · 1.93 KB
/
on_output_summarize.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
local task_list = require("overseer.task_list")
local util = require("overseer.util")
---@type overseer.ComponentFileDefinition
local comp = {
desc = "Summarize task output in the task list",
params = {
max_lines = {
desc = "Number of lines of output to show when detail > 1",
type = "integer",
default = 4,
validate = function(v)
return v > 0
end,
},
},
constructor = function(params)
return {
lines = {},
defer_update_lines = util.debounce(function(self, task, bufnr, num_lines)
if vim.api.nvim_buf_is_valid(bufnr) then
self.lines = util.get_last_output_lines(bufnr, num_lines)
task_list.update(task)
end
end, {
delay = 10,
reset_timer_on_call = true,
}),
on_reset = function(self)
self.lines = {}
end,
on_output = function(self, task, data)
local bufnr = task:get_bufnr()
self.lines = util.get_last_output_lines(bufnr, params.max_lines)
-- Update again after delay because the terminal buffer takes a few millis to be updated
-- after output is received
self.defer_update_lines(self, task, bufnr, params.max_lines)
end,
render = function(self, task, lines, highlights, detail)
local prefix = "out: "
if detail == 1 then
local last_line = self.lines[#self.lines]
if last_line and last_line ~= "" then
table.insert(lines, prefix .. last_line)
table.insert(highlights, { "Comment", #lines, 0, 4 })
table.insert(highlights, { "OverseerOutput", #lines, 4, -1 })
end
else
for _, line in ipairs(self.lines) do
table.insert(lines, prefix .. line)
table.insert(highlights, { "Comment", #lines, 0, 4 })
table.insert(highlights, { "OverseerOutput", #lines, 4, -1 })
end
end
end,
}
end,
}
return comp