@@ -9,6 +9,8 @@ local api = vim.api
99local ColoredPrinter = {}
1010ColoredPrinter .__index = ColoredPrinter
1111
12+ local ns = vim .api .nvim_create_namespace (" colored_printer_hl" )
13+
1214function ColoredPrinter .new ()
1315 local self = setmetatable ({}, ColoredPrinter )
1416 self .color_groups = {}
@@ -20,6 +22,13 @@ function ColoredPrinter.new()
2022 return self
2123end
2224
25+ --- @param buf integer
26+ --- @param start_line integer
27+ --- @param end_line_exclusive integer
28+ function ColoredPrinter :clear (buf , start_line , end_line_exclusive )
29+ vim .api .nvim_buf_clear_namespace (buf , ns , start_line or 0 , end_line_exclusive or - 1 )
30+ end
31+
2332--- @param index integer
2433function ColoredPrinter :get_256_color (index )
2534 -- Standard 16 colors (0-15)
@@ -435,7 +444,7 @@ function ColoredPrinter:set_next_lines(lines, buf, lines_count)
435444 for _ , h in ipairs (hl ) do
436445 -- print("[" .. h.start .. "," .. h.end_ .. ")", get_highlight_def(h.group))
437446
438- vim .hl .range (buf , - 1 , h .group , { lines_count - 1 + i , h .start }, { lines_count - 1 + i , h .end_ })
447+ vim .hl .range (buf , ns , h .group , { lines_count - 1 + i , h .start }, { lines_count - 1 + i , h .end_ })
439448 -- api.nvim_buf_add_highlight(buf, -1, h.group, lines_count - 1 + i, h.start, h.end_)
440449 end
441450 end
0 commit comments