File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,12 @@ local colors = {
12
12
[" 37" ] = " White" , [" 1;37" ] = " BoldWhite" ,
13
13
}
14
14
15
+ local mark = " %"
16
+
15
17
--- Parses a string with ansi-escape codes (colors) into a table
16
18
--- @param str string
17
19
function M .parse (str , opts )
18
20
local colored = {}
19
- local idx = 1
20
21
21
22
local parsed , _ = str :gsub (" (\27 %[[;%d]*m.-\27 %[m)" , function (match )
22
23
local color , text = match :match (" \27 %[([;%d]*)m(.-)\27 %[m" )
@@ -25,21 +26,21 @@ function M.parse(str, opts)
25
26
color = " 35"
26
27
end
27
28
28
- colored [tostring (idx )] = { text = text , color = colors [color ] }
29
- idx = idx + 1
30
-
31
- return idx - 1
29
+ table.insert (colored , { text = text , color = colors [color ] })
30
+ return mark
32
31
end )
33
32
34
33
local out = {}
35
34
for g in parsed :gmatch (" ." ) do
36
- if g : match ( " %d " ) then
37
- table.insert (out , colored [ g ] )
35
+ if g == mark then
36
+ table.insert (out , table.remove ( colored , 1 ) )
38
37
else
39
38
table.insert (out , { text = g , color = " Gray" })
40
39
end
41
40
end
42
41
42
+ assert (vim .tbl_isempty (colored ), " ANSI Parser didn't consume all graph parts" )
43
+
43
44
return out
44
45
end
45
46
You can’t perform that action at this time.
0 commit comments