fix(block): removing ANSI coloring control sequences from message output
Description
Noice assumes users on windows will be using the default cmd.exe shell. As someone who does all windows scripting through powershell, I have set configured my neovim shell to be pwsh
vim.o.shell = "pwsh"
vim.o.shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command"
vim.o.shellpipe = "| Out-File -Encoding UTF8 %s"
vim.o.shellquote = ""
vim.o.shellredir = "| Out-File -Encoding UTF8 %s"
vim.o.shellxquote = ""
When using Powershell 7, colors are pushed to the output with the default variable
$PSStyle.OutputRendering = 'Host'
which colors the terminal screen using ANSI control characters
| (ESC) | Param Start | (Position to color | Param seperator) 1+ | Instruction(color is typically m) |
|---|---|---|---|---|
| ^[ | [ | 1-3 digits | ; | 1 alphabetical |
Example:
**^[[30;1m **
When reading the terminal output, since these characters are being UTF8 encoded through the shell piping, they are showing up in the notify message output. It may be possible to turn the OutputRendering off, however, then there would be no coloring whatsoever.
Resolution
In the same place where CR and LF are removed, add an extra check for ANSI characters
text = text:gsub("%^%[%[[%d;]*%a", "")
Screenshots
Working with CMD
Same command with pwsh as neovim shell
After filtering ANSI characters
This PR is stale because it has been open 30 days with no activity.