2023-10-11 19:09:10 +03:00
|
|
|
ui = {
|
2023-12-26 14:48:33 +03:00
|
|
|
-- FIXME: merge those three into their own modules
|
2023-10-11 19:09:10 +03:00
|
|
|
Alignment = {
|
|
|
|
LEFT = 0,
|
|
|
|
CENTER = 1,
|
|
|
|
RIGHT = 2,
|
|
|
|
},
|
|
|
|
Direction = {
|
|
|
|
HORIZONTAL = false,
|
|
|
|
VERTICAL = true,
|
|
|
|
},
|
2023-10-15 20:03:07 +03:00
|
|
|
Position = {
|
|
|
|
NONE = 0,
|
|
|
|
TOP = 1,
|
|
|
|
RIGHT = 2,
|
2023-10-17 07:34:35 +03:00
|
|
|
BOTTOM = 4,
|
|
|
|
LEFT = 8,
|
|
|
|
ALL = 15,
|
2023-10-15 20:03:07 +03:00
|
|
|
},
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui.highlight_ranges(s, ranges)
|
|
|
|
if ranges == nil or #ranges == 0 then
|
|
|
|
return { ui.Span(s) }
|
|
|
|
end
|
|
|
|
|
|
|
|
local spans = {}
|
|
|
|
local last = 0
|
|
|
|
for _, r in ipairs(ranges) do
|
|
|
|
if r[1] > last then
|
|
|
|
spans[#spans + 1] = ui.Span(s:sub(last + 1, r[1]))
|
|
|
|
end
|
2023-10-13 13:49:24 +03:00
|
|
|
spans[#spans + 1] = ui.Span(s:sub(r[1] + 1, r[2])):style(THEME.manager.find_keyword)
|
2023-10-11 19:09:10 +03:00
|
|
|
last = r[2]
|
|
|
|
end
|
|
|
|
if last < #s then
|
|
|
|
spans[#spans + 1] = ui.Span(s:sub(last + 1))
|
|
|
|
end
|
|
|
|
return spans
|
|
|
|
end
|