Pure: No newline if prompt is first line

Created on 20 Sep 2016  ·  17Comments  ·  Source: sindresorhus/pure

I know the prompt does a newline before the prompt for readability, and I like it that way.

But would it be possible to don't do this newline character when already in the first line as in a new terminal session?

All 17 comments

Could you provide some motivation? It's never really bothered me.

It's definitely doable, but we would have to start keeping state with a new variable wether or not to print the newline character. The clear screen function would also need to _reset_ this state so that no newline is printed then either.

Worth the extra state? Not sure, I'll try to let it sink in for a while.

To better let this sink in, I created the no-initial-newline branch where this is amended and will be running it for a little while.

EDIT: Already noticed one place where this has an unwanted effect, when SSHing into a remote machine with pure there is no newline between the MOTD and the pure prompt :(.

I don't think it's feasible to implement this feature, there are too many problems involved.

  1. We only want to disable the newline when the previous buffer is either clean or invalidated (new terminal window or clear screen)
  2. A new prompt session can be initiated in multiple ways

    • Type zsh (increases $SHLVL)

    • Open tmux (increases $SHLVL)

    • Log in as new user in the current session, e.g. sudo su - (resets $SHLVL to 1)

    • SSH login to a new server

AFAIK there is no way we can detect and keep track of all of these states, not to mention other edge cases that I have yet to think of.

I'm closing this since I don't know how to solve this, although I'm open to discussing this further if someone knows how to fix this.

Would it be possible to disable the new line altogether?

Not officially, but you can check Single line prompt in our Wiki.

See https://github.com/sindresorhus/pure/issues/422#issuecomment-452004045
It's a workaround but it works for me.

what I did to not have a new line when I open a new terminal session was this simple change over prompt_pure_preprompt_render:

if [[ $1 == precmd ]]; then
    # Initial newline, for spaciousness.
    if [[ -z "${prompt_pure_first_line}" ]]; then
        prompt_pure_first_line=1
    else
        print
    fi

Is it fixed? I just installed Pure and see the new line
image

@Alex0007 it's not a bug, as such we have no plans to fix it. If you'd like you can read through the comments on this issue to get a better understanding of the technical limitations on why we _can't_ change the behavior.

@mafredri That'd be something worth having an official FAQ point in the Wiki about - because I didn't find it obvious from reading the issues! (It could be just me though!

This is a usability bug - there's no reason a newline should show unless someone asks for it.

Even if internally its complicated to do - part of the reason we're using the package (if I may be so bold!) is to abstract away these complexities across platforms.

That said - this is a time where I'm baffled on where to begin for making a PR. If only someone had a solution

If I may be a bit nit-picky, this is in no way or form a usability bug. I can't imagine the newline is preventing anyone from using their terminal. Whether or not someone likes the "initial newline" is very much a question preference and taste. Some will like it, others will not. Personally I'm agnostic.

I've outlined in https://github.com/sindresorhus/pure/issues/233#issuecomment-248549416 that there are too many edge cases to implement a logic for "should we show a newline now?". Some of those edge cases are undetectable in Pure, we'll have no way of knowing. So if we implemented it, we'd instead have cases where Pure _doesn't_ show a newline when it _should_. Because of this we've settled on _always show a newline_. It's simple and always works.

If a PR can "fix" this behavior, while also taking into account all the edge cases, we'd be happy to consider it. But alas, we too don't know where to begin 😉.

@mafredri I appreciate your response and sorry on my end for pressing this matter. I think it'd be nice to see this in an FAQ if it's not there.

https://github.com/sindresorhus/pure/issues/233#issuecomment-248549416

Aside: Knowing those tricky edgecases, are you aware p10k does it out of the box, somehow? Absolutely _no idea_ how. This is sorcery to me.

@mafredri I appreciate your response and sorry on my end for pressing this matter. I think it'd be nice to see this in an FAQ if it's not there.

I'll consider adding it, PRs welcome too (we have a FAQ section in the readme) ;).

Aside: Knowing those tricky edgecases, are you aware p10k does it out of the box, somehow? Absolutely no idea how. This is sorcery to me.

Which edge cases did you try?

Here you can see for instance how p10k adds a newline at the bottom instead. It's all compromises :).

Kapture 2020-07-26 at 20 13 18

@mafredri

I'll consider adding it, PRs welcome too (we have a FAQ section in the readme) ;).

Noted!

Which edge cases did you try? + screencast

That was probably it - there was a newline at the bottom maybe. I didn't even notice it.

(I have a bit of a fever now - but I will look through the edgecases more thoroughly when I'm back on my feet)

I think to many - a newline at the bottom is harmless and barely perceptible. A newline at the top is noticeable for every terminal tab, window, tmux pane, etc.

I think to many - a newline at the bottom is harmless and barely perceptible. A newline at the top is noticeable for every terminal tab, window, tmux pane, etc.

For me a newline at the bottom feels more off than one at the top, though. I also tried p10k in tmux and the initial newline is there so it doesn't seem to work in all cases 🤷‍♂️. One feature that p10k also seems to rely quite heavily on is the usage of PROMPT_SP, it results in partial lines filled up with spaces (i.e. lines that don't end on newline). That's one of the things we wanted to eliminate in Pure because it's a nuisance when copying terminal output. Not sure if p10k would accomplish what it does without sp, but this is just, again, to illustrate that there are trade-offs. I have nothing but respect for romkatv and his work on p10k, but it's a very complex project and we're not too keen of adding more complexity, unless absolutely necessary, to Pure.

Was this page helpful?
0 / 5 - 0 ratings