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

gnzh theme: fix "eval" and related scope problems. #4113

Merged
merged 1 commit into from
Sep 19, 2015
Merged

gnzh theme: fix "eval" and related scope problems. #4113

merged 1 commit into from
Sep 19, 2015

Conversation

apjanke
Copy link
Contributor

@apjanke apjanke commented Jul 1, 2015

Fixes #3425.

This clears up issues related to eval and the use of eager vs lazy evaulation in the gnzh theme. The eval was the one causing user-visible problems, but there's a small tangle of related issues, and this addresses them all.

The outcome of this PR is that:

  • Prompt effect escapes are all lazy-evaluated at prompt time, using %F/%f
  • Variables used to build the $PROMPT string are all eager-evaluated at theme loading time
    • Except for ones that deliberately use $(...) to call functions at prompt time
  • Variables are all local-ized

This PR removes the problematic eval usage by switching to normal zsh %F/%f prompt escapes to avoid "eval" and the associated global variables.

There were several local statements that weren't having any effect, because the theme is not loaded in a function, so they were globals. This PR wraps whole thing in an anonymous function so the existing local statements actually work.

But that breaks the theme, because a lot of stuff was done with lazy-evaluated '...' quotes, which relied on those actually being persistent global variables. So this PR switches '...' to eager "..." where needed, so stuff actually works with local variables.

And it local-izes the remaining variables that are used only in prompt construction.

I've tested this on the following, exercising the git, return status, and root detection features, and it looks good.

  • Mac OS X 10.9.5 with iTerm2 and Terminal.app
  • Debian 7 using Konsole, xterm, and urxvt
  • Cygwin/Windows 7 using mintty
    Could use some more testers for urxvt and the console on Linux distros that were having this problem, and for RVM.

@mcornella
Copy link
Member

👍 /cc @robbyrussell

@maehne
Copy link

maehne commented Sep 4, 2015

I tried out this pull request to fix issue #3425 on Debian Jessie. It fixes indeed the eval error message when logging directly into a text console. However, the fix has the side effect that now the arrow part on the second line and the command you enter after it is displayed in bright white (and in KDE Konsole additionally with a thicker font). The start of the arrow on the first line is displayed in the normal gray tone of the text console.

Switch to normal zsh %F/%f prompt escapes to avoid "eval" and extra variables.
Wrap whole thing in anonymous function so the existing `local`
statements actually work. Then switch '...' to eager "..." so
stuff actually works with local variables. And local-ize the
remaining variables that are used only in prompt construction.
@apjanke
Copy link
Contributor Author

apjanke commented Sep 4, 2015

Looks like an unclosed %B in the directory display was leaking bold text in to the rest of the prompt. %f won't reset %B like the old $PR_NO_COLOR would reset bold; it needs to be closed separately with a %b.

Some terminals are set to display bold text in a bright color, which is why it looked brighter on your terminal. I didn't notice this while testing because I have the bold=bright setting off in my terminals, and bold doesn't look all that different from normal text to me. But it's clearly visible when toggling the bold font on and off in the profile.

I've amended the commit to fix this. Give it another try.

@maehne
Copy link

maehne commented Sep 4, 2015

Thank you for your quick reaction to my report! I just tested your fix and now the gnzh theme works nicely without any error messages or coloring problems. 👍

@apjanke
Copy link
Contributor Author

apjanke commented Sep 4, 2015

Great. I think this is ready to merge.

@mcornella
Copy link
Member

👍 /cc @robbyrussell

robbyrussell added a commit that referenced this pull request Sep 19, 2015
gnzh theme: fix "eval" and related scope problems.
@robbyrussell robbyrussell merged commit adaf89c into ohmyzsh:master Sep 19, 2015
@apjanke apjanke deleted the gnzh-remove-eval branch September 20, 2015 05:10
nunogt pushed a commit to nunogt/oh-my-zsh that referenced this pull request Jan 25, 2016
gnzh theme: fix "eval" and related scope problems.
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.

4 participants