-
-
Notifications
You must be signed in to change notification settings - Fork 973
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
There are lots of extra spaces in terminal output (caused by PROMPT_CR) #127
Comments
I actually added because I was so annoyed that so many tools didn't print the trailing newline. |
Ah, I see. It should be possible to read the cursor position from the terminal though, if it's not the first character, print an extra newline. |
👍 |
I found a solution to this, but I don't think I want to merge it as it requires toggling echo of the terminal ( diff --git a/pure.zsh b/pure.zsh
index f6fd34d..82ba2f4 100644
--- a/pure.zsh
+++ b/pure.zsh
@@ -98,6 +98,21 @@ prompt_pure_preprompt_render() {
# if executing through precmd, do not perform fancy terminal editing
if [[ "$1" == "precmd" ]]; then
+ {
+ local cursor_position
+ local IFS=";"
+ # stty -echo prevent output from being echoed to terminal
+ stty -echo
+ # printing \033[6n to the terminal outputs current cursor position
+ print -n "\033[6n"
+ # re-enable echo
+ stty echo
+ # read output from print command and prevent outputting to terminal
+ read -s -r -d "R" -A cursor_position
+ # if cursor position is not 1, then output is missing a newline at the end, print it
+ [[ "${cursor_position[2]}" != "1" ]] && print
+ }
+
print -P "\n${prompt}"
else
# only redraw if prompt has changed
@@ -243,7 +258,7 @@ prompt_pure_setup() {
# if output doesn't end with a newline
export PROMPT_EOL_MARK=''
- prompt_opts=(cr subst percent)
+ prompt_opts=(subst percent)
zmodload zsh/datetime
autoload -Uz add-zsh-hook |
Yeah, looks too hacky. Gonna hit us at some point. I guess it would be better to just remove |
|
Or we could just close this issue because this can easily be achieved by setting unsetopt prompt_cr after prompt pure |
PROMPT_CR leaves too many extra spaces. Now that I have a blank line separating the preprompt and the output of the previous command, I can afford to throw out PROMPT_CR. Added bonus: we also have a clear visual distinction of commands that print a trailing newline and commands that do not (bad citizens, except pbpaste). See also sindresorhus/pure#127.
@forivall sorry for not responding to your comment. Regarding @sindresorhus I'll leave it up to you to decide if we remove |
I totally hate it. Probably worth submitting a patch to Zsh. |
👍 Or even just opening an issue over there ;)
Remove it. |
Defining
cr
inprompt_opts
causes zsh to print a carriage return (basically #$COLUMN
of spaces) after the last output line to make sure the prompt does not overwrite output in the terminal. Sincepure
uses a newline in it's pre-prompt this is a non-issue and the spaces are a nuisance when copying text from the terminal.Sample with
![](https://camo.githubusercontent.com/c497d40816f3749ffe3efdcced3fd5029ad15c0d14d34f0dadd2dabf0c26810a/68747470733a2f2f7777772e64726f70626f782e636f6d2f732f31353130637735616f746c356f69392f53637265656e73686f74253230323031352d30362d303225323031332e32332e35382e706e673f646c3d31)
cr
:Sample without
![](https://camo.githubusercontent.com/77262f8ba334bea453241f713cb0a4d30361b5ecf4d9eb1b737342bd7d33baa9/68747470733a2f2f7777772e64726f70626f782e636f6d2f732f786c7163767236396a7679756772682f53637265656e73686f74253230323031352d30362d303225323031332e32382e32362e706e673f646c3d31)
cr
:Between the two samples we see that if the output doesn't end with a newline as with
echo -n
then there's no breathing space between the output and the new prompt. In my opinion this is actually more correct behavior as it tells the user the output was missing a newline at the end.I will try to run this for a while locally for a while and see if I spot any unwanted side-effects.
The text was updated successfully, but these errors were encountered: