Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve preprompt on Ctrl+L #147

Closed
wants to merge 3 commits into from
Closed

Preserve preprompt on Ctrl+L #147

wants to merge 3 commits into from

Conversation

mafredri
Copy link
Collaborator

As discussed in #145 This PR fixes clear screen in pure (where the preprompt is missing when issuing Ctrl+L).

Due to third-party libraries doing whatever they want, I've decided to take a more fragile, but safer approach in this PR (see 4961520 for details).

Register a custom zle widget to clear screen using ansi codes instead of
relying on builtin behavior.
@@ -153,6 +153,19 @@ antigen bundle sindresorhus/pure

## FAQ

### My preprompt is missing when I clear the screen with Ctrl+L

Pure doesn't register it's custom *clear-screen* widget if it has been previously modified. If you haven't registered your
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's => its

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

Because some external zsh modules take control of your zsh widgets in an
unobvious way, the user needs to know what is happening and how to fix
it. I think it's better to let it break our custom clearing and let the
user know why it boke.

Trying to do the same as zsh-syntax-hilighting might result in odd cases
where zsh-syntax-highlighting registers the builtin clear-screen widget
and pure wrapping the custom highlighting widget resulting in multiple
clear screens.
@mafredri
Copy link
Collaborator Author

Amended comments on readme and did a force push of the branch.

# enable output to terminal
zle -I
# clear screen and move cursor to (0, 0)
print -n "\e[2J\e[0;0H"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use single-quotes? I kinda like to use single-quotes when there's no variable expansion going on to make the intent clear. Does that make sense? (I'm still not sure about it).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single-quotes would work, no doubt. Although, when working with shell scripts I kind of prefer double quotes. It's easier to add a variable later (no need to convert quotes) and you don't really need to think about which to use. The exception I usually do is when you have double-quotes inside the string, then I might wrap it in single-quotes.

I'm fine with either as long as we stick to one way of doing it :)!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's stick with single-quotes wherever possible for now then. We can always change later if that feels weird.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll update the PR.

@sindresorhus
Copy link
Owner

Tried it now. Works good. I always bothered me that the preprompt would disappear and I had no idea it was fixable :)

@mafredri
Copy link
Collaborator Author

Yeah, I was kind of bothered by it too, and if @zmwangx hadn't brought it up, I probably wouldn't have investigated it further, so thanks to him (and his input)! :)

@sindresorhus sindresorhus changed the title Clear screen fix Preserve preprompt on Ctrl+L Jul 18, 2015
@mafredri mafredri closed this in ba1f064 Jul 18, 2015
@sindresorhus sindresorhus deleted the clear-screen-fix branch July 18, 2015 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants