You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh, I'm sorry, I didn't mean to leave you hanging. Here's what I have so far, it works on Windows 10 and Linux, even in VS Code ... but obviously not anywhere that ANSI escape sequences don't work (e.g. ISE): http://poshcode.org/6485
Jason Shirk (@lzybkr)
I try to follow your demo to get color on my prompt and when I login it work I see my color prompt but the moment I type something the escape character break.
any ideas?
function prompt {
return "$([char]0x1b)[91m >_ $([char]0x1b)[0m"
}
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
_
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
You probably already know this but avoiding Write-Host doesn't prevent double execution of the prompt function. It just makes it a bit less obvious:
In fact, what I notice with the prompt function is that the first two or three characters from the first line of my prompt get redisplayed on the second line as soon as I type any character:
With some small changes I was able to drop the PSReadLine master branch into the PowerShell git repo (using tag v6.0.0-beta.8) and build it on Linux. It's mostly working! Looks fine in a bare xterm, but try running powershell under screen--you should get some junk at the prompt as soon as you start typing.
The junk I'm seeing is [37m[40m[0m, which are parts of SGR sequences: set foreground color white, set background black, set normal. If they're showing up for you (i.e. if you can reproduce), try seeing what's actually getting written to the terminal (with strace or similar).
I can reproduce, and I'm strace noob, but I can't see anything in the output that looks like what I'm sending, either with v1.2 (which works in screen) or in v2.0 which doesn't.
Sorry, brainfart--you would want to strace the screen daemon process, so that you can see what powershell is writing to it. Here's what strace -p $PIDGOESHERE -e read=all -e write=all shows after I press a key to make the junk appear at the prompt (this asks to produce a hexdump of the full contents of reads and writes to any of that PID's file descriptors):
The last read is what powershell is writing to screen's pty, and the write is what the screen daemon is writing to the attached client (which shows up on our terminal). Looks like some of the sequences are being output with each character as a 16-bit/.NET-style char rather than what was actually intended.
I had to set Console.OutputEncoding = Encoding.Unicode for CJK characters, and that definitely fixed an issue on Windows and it seems like it also fixed CJK on Linux, see #542.
So the quick fix is to just remove where I do that, but I'm not sure that's the right fix.
Mark Laws (@drvink) - I just pushed what should fix the screen problem - I should have used UTF8 instead of Unicode for the output encoding - the CJK issue still seems fixed, so hopefully screen will be fine too.
Jason Shirk (@lzybkr) Thanks! I don't have time to test it at the moment, but that sounds like the right fix to me as well. I'll try to comment when I get a chance to rebuild with the new changes, but if you aren't getting the incorrectly-emitted escape sequences when you strace, it's most likely fixed now.
Activity
lzybkr commentedon Nov 9, 2016
From @lukemgriffith on August 18, 2016 23:11
I'm also seeing the same on MacOS 10.11.6
I see the verbose "Test" twice.
lzybkr commentedon Nov 9, 2016
From Joel Bennett (@Jaykul) on August 18, 2016 23:38
Ditto for Ubuntu 16.04
I had to stop using Write-Host ... now using escape sequences for color ;-)
lzybkr commentedon Nov 9, 2016
From myyc on August 20, 2016 10:50
Joel Bennett (@Jaykul) can you share details? it seems ANSI escape sequences aren't supported out of the box
lzybkr commentedon Nov 9, 2016
From Paul (@whatevergeek) on August 20, 2016 11:21
myyc which details you need?
my hunch is that whatever posted by write-host
gets posted twice
i'm still in the process of getting the source built on my machine... will try to help also once i get the setup done :-)
lzybkr commentedon Nov 9, 2016
From myyc on August 20, 2016 11:26
Paul (@whatevergeek) details on how to use escape sequences instead of write-host ...
lzybkr commentedon Nov 9, 2016
From theaquamarine on August 22, 2016 22:45
myyc there's a bit of an example here dahlbyk/posh-git#282 (comment)
lzybkr commentedon Nov 9, 2016
From Joel Bennett (@Jaykul) on August 23, 2016 0:5
Oh, I'm sorry, I didn't mean to leave you hanging. Here's what I have so far, it works on Windows 10 and Linux, even in VS Code ... but obviously not anywhere that ANSI escape sequences don't work (e.g. ISE): http://poshcode.org/6485
rspaulino commentedon Dec 29, 2016
Jason Shirk (@lzybkr)
I try to follow your demo to get color on my prompt and when I login it work I see my color prompt but the moment I type something the escape character break.
any ideas?
function prompt {
return "$([char]0x1b)[91m >_ $([char]0x1b)[0m"
}
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
[91clear
rkeithhill commentedon Jan 27, 2017
You probably already know this but avoiding

Write-Hostdoesn't prevent double execution of the prompt function. It just makes it a bit less obvious:In fact, what I notice with the prompt function is that the first two or three characters from the first line of my prompt get redisplayed on the second line as soon as I type any character:

21 remaining items
drvink commentedon Oct 20, 2017
With some small changes I was able to drop the PSReadLine master branch into the PowerShell git repo (using tag v6.0.0-beta.8) and build it on Linux. It's mostly working! Looks fine in a bare xterm, but try running powershell under
screen--you should get some junk at the prompt as soon as you start typing.lzybkr commentedon Oct 20, 2017
The binary built from this repo works in PowerShell Core all platforms too.
Artifacts in screen are new? I wonder if I'm using an escape sequence that isn't supported under screen.
drvink commentedon Oct 20, 2017
The junk I'm seeing is
[37m[40m[0m, which are parts of SGR sequences: set foreground color white, set background black, set normal. If they're showing up for you (i.e. if you can reproduce), try seeing what's actually getting written to the terminal (withstraceor similar).lzybkr commentedon Oct 20, 2017
I can reproduce, and I'm
stracenoob, but I can't see anything in the output that looks like what I'm sending, either with v1.2 (which works inscreen) or in v2.0 which doesn't.drvink commentedon Oct 20, 2017
Sorry, brainfart--you would want to
stracethescreendaemon process, so that you can see whatpowershellis writing to it. Here's whatstrace -p $PIDGOESHERE -e read=all -e write=allshows after I press a key to make the junk appear at the prompt (this asks to produce a hexdump of the full contents of reads and writes to any of that PID's file descriptors):The last
readis whatpowershellis writing to screen's pty, and thewriteis what the screen daemon is writing to the attached client (which shows up on our terminal). Looks like some of the sequences are being output with each character as a 16-bit/.NET-stylecharrather than what was actually intended.lzybkr commentedon Oct 20, 2017
Thanks, that's super helpful.
I had to set
Console.OutputEncoding = Encoding.Unicodefor CJK characters, and that definitely fixed an issue on Windows and it seems like it also fixed CJK on Linux, see #542.So the quick fix is to just remove where I do that, but I'm not sure that's the right fix.
lzybkr commentedon Nov 2, 2017
Mark Laws (@drvink) - I just pushed what should fix the
screenproblem - I should have usedUTF8instead ofUnicodefor the output encoding - the CJK issue still seems fixed, so hopefullyscreenwill be fine too.drvink commentedon Nov 3, 2017
Jason Shirk (@lzybkr) Thanks! I don't have time to test it at the moment, but that sounds like the right fix to me as well. I'll try to comment when I get a chance to rebuild with the new changes, but if you aren't getting the incorrectly-emitted escape sequences when you
strace, it's most likely fixed now.lzybkr commentedon Nov 4, 2017
I'll have an official prerelease build out next week if you want to verify this is fixed, otherwise you can grab a build out of appveyor here.
pcgeek86 commentedon Nov 9, 2017
When I extract the ZIP artifact, it has backslashes in the file names, instead of forward slashes, which breaks the module file paths.
lzybkr commentedon Nov 10, 2017
Compress-Archiveis creating the archive - but I assume that will be a non-issue when installing from the PowerShell Gallery.drvink commentedon Nov 16, 2017
Jason Shirk (@lzybkr) Just wanted to report that things work fine under
screennow. Thanks!SteveL-MSFT commentedon Nov 16, 2017
Trevor Sullivan (@pcgeek86) the backslashes is an issue with
compress-archivewhich I opened here https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/48pcgeek86 commentedon Nov 17, 2017
Steve Lee (@SteveL-MSFT) Cool, thank you for calling that out!