PSFzf icon indicating copy to clipboard operation
PSFzf copied to clipboard

Special characters are replaced with question marks after PSFzf runs (but not after fzf by itself)

Open jmoore34 opened this issue 4 years ago • 5 comments

When PSFzf is used with a powerline (e.g. oh-my-posh), the special characters are replaced with question marks after fzf runs.

image

Reproduction steps:

  1. Install oh-my-posh and choose a theme that uses special characters
  2. Invoke PSFzf, and then make a selection or close fzf

Tested on latest version (2.2.6)

Additional note: This issue does not occur when fzf is called manually from the command line

jmoore34 avatar Feb 26 '21 03:02 jmoore34

Unfortunately this is due to a workaround when fzf is invoked from a PSReadline handler. I have to call PSReadline's InvokePrompt to redraw the prompt as PSReadline won't automatically redraw the prompt after a child process modifies the text buffer. I'm not sure how to fix this one, unless this is fixed in PSReadline.

kelleyma49 avatar Apr 24 '21 18:04 kelleyma49

Should someone file this bug against PSReadline then?

segevfiner avatar Sep 14 '21 16:09 segevfiner

Submitted https://github.com/PowerShell/PSReadLine/issues/2866

segevfiner avatar Sep 18 '21 12:09 segevfiner

I worked around this locally by adding:

function script:InvokePrompt()
{
	$previousOutputEncoding = [Console]::OutputEncoding
	[Console]::OutputEncoding = [Text.Encoding]::UTF8
	
	try {
		[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
	} finally {
		[Console]::OutputEncoding = $previousOutputEncoding
	}
}

And calling that instead of calling [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() directly. Not sure if this is something you will actually want in a pull request..., I said the same about this in https://github.com/PowerShell/PSReadLine/issues/2866#issuecomment-960788773, but who knows if it will ever get any attention... 🤷‍♂️

P.S. Does adding script: do anything? Isn't that already the default scope of functions defined at the script level?

I also set Set-PSReadLineOption -ExtraPromptLineCount 2 since it seems to redraw the prompt better that way. (Using starship prompt)

segevfiner avatar Nov 04 '21 15:11 segevfiner

Thank for for the investigation! I added your workaround and tested it locally. it looks great!

I created a prerelease version with your change: https://www.powershellgallery.com/packages/PSFzf/2.3.1-alpha

kelleyma49 avatar Nov 06 '21 19:11 kelleyma49