Skip to content

Commit

Permalink
fix(input): don't filter ^M and <cr> for the command line (#734)
Browse files Browse the repository at this point in the history
* fix(input): don't filter ^M and <cr> for the command line

* refacor: is_cmdline => fix_cr

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
  • Loading branch information
Sam-programs and folke committed Mar 24, 2024
1 parent 01b2b53 commit d29b26c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lua/noice/text/block.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local require = require("noice.util.lazy")

local Highlight = require("noice.text.highlight")
local Util = require("noice.util")
local NuiLine = require("nui.line")
local Object = require("nui.object")

Expand All @@ -10,6 +9,7 @@ local Object = require("nui.object")

---@class NoiceBlock
---@field _lines NuiLine[]
---@field fix_cr boolean?
---@overload fun(content?: NoiceContent|NoiceContent[], highlight?: string|table): NoiceBlock
local Block = Object("Block")

Expand Down Expand Up @@ -110,7 +110,7 @@ function Block:_append(content, highlight)
if #self._lines == 0 then
table.insert(self._lines, NuiLine())
end
if type(content) == "string" and true then
if type(content) == "string" and self.fix_cr ~= false then
-- handle carriage returns. They overwrite the line from the first character
local cr = content:match("^.*()[\r]")
if cr then
Expand Down Expand Up @@ -167,8 +167,10 @@ function Block:append(contents, highlight)
---@type number|string|table, string
local attr_id, text = unpack(content)
-- msg_show messages can contain invalid \r characters
text = text:gsub("%^M", "\r")
text = text:gsub("\r\n", "\n")
if self.fix_cr ~= false then
text = text:gsub("%^M", "\r")
text = text:gsub("\r\n", "\n")
end

---@type string|table|nil
local hl_group
Expand Down
1 change: 1 addition & 0 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ end
---@param text_only? boolean
function Cmdline:format(message, text_only)
local format = self:get_format()
message.fix_cr = false

if format.icon then
message:append(NoiceText.virtual_text(format.icon, format.icon_hl_group))
Expand Down

0 comments on commit d29b26c

Please sign in to comment.