1
1
local require = require (" noice.util.lazy" )
2
2
3
3
local Highlight = require (" noice.text.highlight" )
4
+ local Util = require (" noice.util" )
4
5
local NuiLine = require (" nui.line" )
5
6
local Object = require (" nui.object" )
6
7
@@ -109,6 +110,15 @@ function Block:_append(content, highlight)
109
110
if # self ._lines == 0 then
110
111
table.insert (self ._lines , NuiLine ())
111
112
end
113
+ if type (content ) == " string" and true then
114
+ -- handle carriage returns. They overwrite the line from the first character
115
+ local cr = content :match (" ^.*()[\r ]" )
116
+ if cr then
117
+ table.remove (self ._lines )
118
+ table.insert (self ._lines , NuiLine ())
119
+ content = content :sub (cr + 1 )
120
+ end
121
+ end
112
122
return self ._lines [# self ._lines ]:append (content , highlight )
113
123
end
114
124
@@ -156,6 +166,8 @@ function Block:append(contents, highlight)
156
166
-- Handle newlines
157
167
--- @type number | string | table , string
158
168
local attr_id , text = unpack (content )
169
+ -- msg_show messages can contain invalid \r characters
170
+ text = text :gsub (" %^M" , " \r " )
159
171
text = text :gsub (" \r\n " , " \n " )
160
172
161
173
--- @type string | table | nil
@@ -168,23 +180,12 @@ function Block:append(contents, highlight)
168
180
169
181
while text ~= " " do
170
182
local nl = text :find (" \n " )
183
+ local line = nl and text :sub (1 , nl - 1 ) or text
184
+ self :_append (line , hl_group )
171
185
if nl then
172
- local str = text :sub (1 , nl - 1 )
173
-
174
- -- handle carriage returns. They overwrite the line from the first character
175
- if str :find (" \r " ) then
176
- local parts = vim .split (str , " \r " , { plain = true })
177
- str = " "
178
- for _ , p in ipairs (parts ) do
179
- str = p .. str :sub (p :len () + 1 )
180
- end
181
- end
182
-
183
- self :_append (str , hl_group )
184
186
self :newline ()
185
187
text = text :sub (nl + 1 )
186
188
else
187
- self :_append (text , hl_group )
188
189
break
189
190
end
190
191
end
0 commit comments