Skip to content

Support for RPROMPT? #261

Closed
Closed

Description

@rschmitt

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:

  1. I can write an RPROMPT, wrap around to the next line, and write the regular prompt()
  2. 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.

Activity

  1. rkeithhill commented on Jul 4, 2015

    @rkeithhill
    Contributor

    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

  2. rschmitt commented on Jul 4, 2015

    @rschmitt
    Author

    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.

  3. rkeithhill commented on Jul 4, 2015

    @rkeithhill
    Contributor

    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?

  4. rschmitt commented on Jul 4, 2015

    @rschmitt
    Author

    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?)

  5. rkeithhill commented on Jul 5, 2015

    @rkeithhill
    Contributor

    That is true for V4 and earlier. Later builds of V5 preview ship with PSReadline built-in and load it by default.

  6. rschmitt commented on Jul 5, 2015

    @rschmitt
    Author

    Evidently I'm running PS5 (on Windows 8.1), so this may in fact be a regression in PSReadline after all.

  7. lzybkr commented on Oct 31, 2017

    @lzybkr
    Contributor

    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?

  8. lzybkr commented on Jun 12, 2019

    @lzybkr
    Contributor

    Closing since recent releases behave as described in this comment. It's not perfect, but maybe good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions