noice.nvim icon indicating copy to clipboard operation
noice.nvim copied to clipboard

fix(block): removing ANSI coloring control sequences from message output

Open Avsilver opened this issue 6 months ago • 1 comments

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

image

Same command with pwsh as neovim shell

image

After filtering ANSI characters

image

Avsilver avatar Jul 07 '25 02:07 Avsilver

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Aug 06 '25 02:08 github-actions[bot]