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
In zsh, the RPROMPT environment variable allows right-aligned prompt text to be defined; it's a great place to stick things like the current time, git status information, and so on. (I think bash has an equivalent called RPS1.) I'd love to be able to have something like this in PS, but I haven't been able to figure out a way to do it. I can only get so close:
I can write an RPROMPT, wrap around to the next line, and write the regular prompt()
I can write an RPROMPT on the same line as the prompt() (by going through RawUI), but it will vanish once I start typing
I'm not sure if this sort of thing is within PSReadLine's purview at all, but I'd at least like to get an opinion from someone who knows PS really well.
PSReadline is a replacement for PowerShell's line editing features (including command history). I don't think prompt functionality fits into PSReadline's mission. BTW here are few samples of prompt functions:
I don't need a sample prompt function, I'm specifically referring to right-aligned text at the end of the input line. If you try the "Cursor Movement" prompt from the second link, you'll see the problem I'm referring to: the text you wrote vanishes once you start typing. (Maybe this worked in an older version of PS, but it no longer does.)
PSReadline isn't responsible for prompt functionality specifically, but it is at least tangentially involved in rendering the prompt. It's also in a position to provide certain extension points for interactive functionality. As a ridiculous example, PSReadline could offer a hook (maybe it already does?) to execute a function after each keypress. Such a function could re-draw the RPROMPT after each keypress. This implementation would suck (it would be really slow and flicker a lot), but the proof-of-concept is there.
For all I know, it might also be possible for the implementation of PSReadline to be tweaked in such a way that text to the right of the cursor is no longer clobbered upon keypress. These are the sorts of things I'd like some feedback on.
Oh I see, PSReadline is clobbering part of your prompt because it doesn't know it's there because you're manipulating the console buffer directly, right?
The same thing seems to happen when I disable PSReadline, assuming that that's just a matter of commenting out the Import-Module line in my $profile. (Is it?)
With #561 - PSReadLine will no longer clobber your RPROMPT immediately, but if you type a long enough command line, it will eventually start overwriting it.
Activity
rkeithhill commentedon Jul 4, 2015
PSReadline is a replacement for PowerShell's line editing features (including command history). I don't think prompt functionality fits into PSReadline's mission. BTW here are few samples of prompt functions:
http://stackoverflow.com/questions/1338453/custom-powershell-prompts
http://mshforfun.blogspot.com/2006/05/perfect-prompt-for-windows-powershell.html
rschmitt commentedon Jul 4, 2015
I don't need a sample prompt function, I'm specifically referring to right-aligned text at the end of the input line. If you try the "Cursor Movement" prompt from the second link, you'll see the problem I'm referring to: the text you wrote vanishes once you start typing. (Maybe this worked in an older version of PS, but it no longer does.)
PSReadline isn't responsible for prompt functionality specifically, but it is at least tangentially involved in rendering the prompt. It's also in a position to provide certain extension points for interactive functionality. As a ridiculous example, PSReadline could offer a hook (maybe it already does?) to execute a function after each keypress. Such a function could re-draw the RPROMPT after each keypress. This implementation would suck (it would be really slow and flicker a lot), but the proof-of-concept is there.
For all I know, it might also be possible for the implementation of PSReadline to be tweaked in such a way that text to the right of the cursor is no longer clobbered upon keypress. These are the sorts of things I'd like some feedback on.
rkeithhill commentedon Jul 4, 2015
Oh I see, PSReadline is clobbering part of your prompt because it doesn't know it's there because you're manipulating the console buffer directly, right?
rschmitt commentedon Jul 4, 2015
The same thing seems to happen when I disable PSReadline, assuming that that's just a matter of commenting out the
Import-Moduleline in my $profile. (Is it?)rkeithhill commentedon Jul 5, 2015
That is true for V4 and earlier. Later builds of V5 preview ship with PSReadline built-in and load it by default.
rschmitt commentedon Jul 5, 2015
Evidently I'm running PS5 (on Windows 8.1), so this may in fact be a regression in PSReadline after all.
lzybkr commentedon Oct 31, 2017
With #561 - PSReadLine will no longer clobber your RPROMPT immediately, but if you type a long enough command line, it will eventually start overwriting it.
So not quite fixed, but good enough?
lzybkr commentedon Jun 12, 2019
Closing since recent releases behave as described in this comment. It's not perfect, but maybe good enough.