Skip to content

Commit 7a80b69

Browse files
committed
WIP: take 2 for renderer architecture
1 parent eabd6a5 commit 7a80b69

11 files changed

Lines changed: 1963 additions & 416 deletions

File tree

lua/opencode/ui/renderer.lua

Lines changed: 341 additions & 160 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
local M = {}
2+
3+
function M.is_append(old_lines, new_lines)
4+
if type(old_lines) ~= 'table' or type(new_lines) ~= 'table' then
5+
return false
6+
end
7+
8+
if #new_lines <= #old_lines then
9+
return false
10+
end
11+
12+
for i = #old_lines, 1, -1 do
13+
if old_lines[i] ~= new_lines[i] then
14+
return false
15+
end
16+
end
17+
18+
return true
19+
end
20+
21+
function M.tail_lines(old_lines, new_lines)
22+
return { unpack(new_lines, #old_lines + 1) }
23+
end
24+
25+
function M.tail_extmarks(row_offset, extmarks)
26+
local out = {}
27+
28+
for _, extmark in ipairs(extmarks or {}) do
29+
if extmark.row >= row_offset then
30+
out[#out + 1] = {
31+
row = extmark.row - row_offset,
32+
col = extmark.col,
33+
opts = vim.deepcopy(extmark.opts),
34+
}
35+
end
36+
end
37+
38+
return out
39+
end
40+
41+
function M.can_append(old_rendered, new_rendered)
42+
if type(old_rendered) ~= 'table' or type(new_rendered) ~= 'table' then
43+
return false
44+
end
45+
46+
if not M.is_append(old_rendered.lines, new_rendered.lines) then
47+
return false
48+
end
49+
50+
if not vim.deep_equal(old_rendered.actions or {}, new_rendered.actions or {}) then
51+
return false
52+
end
53+
54+
local old_extmarks = old_rendered.extmarks or {}
55+
local new_extmarks = new_rendered.extmarks or {}
56+
if #new_extmarks < #old_extmarks then
57+
return false
58+
end
59+
60+
for index = 1, #old_extmarks do
61+
if not vim.deep_equal(old_extmarks[index], new_extmarks[index]) then
62+
return false
63+
end
64+
end
65+
66+
return true
67+
end
68+
69+
return M

0 commit comments

Comments
 (0)