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

Add support for configuring colors with zstyle #472

Merged
merged 9 commits into from
Jun 20, 2019

Conversation

bricewge
Copy link
Contributor

@bricewge bricewge commented May 5, 2019

Following the discussion at #306 this PR add the capacity to change the colors of pure by using zstyle to avoid polluting the global name space.

Available colors:

  • branch
  • error
  • exec_time
  • git_arrow
  • host
  • path
  • root
  • success
  • user
  • virtualenv

Fixes #126
Fixes #303
Fixes #306
Fixes #389
Closes #256
Closes #450

EDIT: Add requested colors.

@eladchen
Copy link

Any chance this will be merged soon?

pure.zsh Outdated Show resolved Hide resolved
pure.zsh Outdated Show resolved Hide resolved
@bricewge bricewge force-pushed the zstyle-colors branch 3 times, most recently from c210cee to 044b21c Compare June 3, 2019 12:00
pure.zsh Outdated Show resolved Hide resolved
@sindresorhus sindresorhus changed the title configure colors with zstyle Add support for configuring colors with zstyle Jun 10, 2019
readme.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @bricewge, much appreciated!

pure.zsh Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
pure.zsh Outdated Show resolved Hide resolved
pure.zsh Outdated Show resolved Hide resolved
readme.md Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
pure.zsh Outdated Show resolved Hide resolved
@LitoMore LitoMore mentioned this pull request Jun 11, 2019
@bricewge bricewge force-pushed the zstyle-colors branch 3 times, most recently from 6570bea to 3f018b0 Compare June 12, 2019 20:03
@bricewge
Copy link
Contributor Author

The updated PR add branch:cached color. allow live updating of all the colors and show how to 2 state colors at one.
@mafredri @sindresorhus Can I get a second round of review?

Copy link
Collaborator

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Thanks, this is shaping up nicely!

There were a few quirks with zstyle that caught my eye, but in general I'm liking the look of this.

pure.zsh Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@LitoMore
Copy link
Contributor

Can you fix the merge conflict?

@bricewge
Copy link
Contributor Author

@LitoMore Thanks for the heads-up, I forgot that your PR got merged.

Available colors:
- exec_time
- git:arrow
- git:branch
- git:branch:cached
- host
- path
- prompt:error
- prompt:success
- user
- user:root, default color changed from `white` to `default`
- virtualenv
Copy link
Collaborator

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Aww yeah 😎! LGTM!

Did a quick trial run, tweaking the colors is pretty fun.

zstyle :prompt:pure:exec_time color 225
zstyle :prompt:pure:git:arrow color 220
zstyle :prompt:pure:git:branch color 106
zstyle :prompt:pure:host color 30
zstyle :prompt:pure:path color 230
zstyle :prompt:pure:prompt:error color 196
zstyle :prompt:pure:prompt:success color 222
zstyle :prompt:pure:user color 36

image

@sindresorhus
Copy link
Owner

I think this should be documented #472 (comment) as being possible.

readme.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@bricewge bricewge left a comment

Choose a reason for hiding this comment

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

I think this should be documented #472 (comment) as being possible.

What do you mean? If it's deleting a style, I don't think it's necessary because zstyle use the most specific and latest zstyle when queried and it will only make sense when testing. Or do you mean that when a style is deleted it return to it's default value which I also don't think is needed to be specified since it follow the principle of least astonishment.

zstyle usage is best left to the manual because of all it's quirk, even @mafredri already fell into on of it's pothole #472 (comment).

readme.md Outdated Show resolved Hide resolved
readme.md Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated
As explained in ZSH's[manual](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting) color values can be:
- a decimal integer up to the maximal number of color your terminal support
- the name of one of the following nine colours: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white` and `default` (the terminal’s default foreground)
- ‘#’ followed by an RGB triplet in hexadecimal format (ex. `#424242`), *only* if your terminal support 24bit colors or when the module [`zsh/nearcolor`](http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fnearcolor-Module) is loaded
Copy link
Owner

Choose a reason for hiding this comment

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

We should show an example of loading zsh/nearcolor and using a HEX color in the Example section. I think a lot of users will want this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

readme.md Outdated
@@ -96,6 +96,11 @@ prompt pure

## Colors

As explained in ZSH's[manual](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting) color values can be:
- a decimal integer up to the maximal number of color your terminal support
Copy link
Owner

Choose a reason for hiding this comment

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

What does the decimal integer represent? How can users find the number they want? Those are some questions we should answer.

In general, we should not force users to read the horrible ZSH manual to achieve things most user would want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have explained what it represent but the way to find the which color that I can't explain because it is terminal specific.

Now I understand the reason behind all your comments on the documentation side. And I'm happy to see I'm not the only one thinking that this manual isn't well written! Hell I have even found this gem in the manual:

[...] the Zsh Development Group accepts no responsibility for any brain damage which may occur during the reading [...]

Copy link
Contributor Author

@bricewge bricewge left a comment

Choose a reason for hiding this comment

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

Is it good this time?

readme.md Outdated
@@ -96,6 +96,11 @@ prompt pure

## Colors

As explained in ZSH's[manual](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting) color values can be:
- a decimal integer up to the maximal number of color your terminal support
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have explained what it represent but the way to find the which color that I can't explain because it is terminal specific.

Now I understand the reason behind all your comments on the documentation side. And I'm happy to see I'm not the only one thinking that this manual isn't well written! Hell I have even found this gem in the manual:

[...] the Zsh Development Group accepts no responsibility for any brain damage which may occur during the reading [...]

readme.md Outdated
As explained in ZSH's[manual](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting) color values can be:
- a decimal integer up to the maximal number of color your terminal support
- the name of one of the following nine colours: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white` and `default` (the terminal’s default foreground)
- ‘#’ followed by an RGB triplet in hexadecimal format (ex. `#424242`), *only* if your terminal support 24bit colors or when the module [`zsh/nearcolor`](http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fnearcolor-Module) is loaded
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

readme.md Outdated Show resolved Hide resolved
pure.zsh Outdated Show resolved Hide resolved
@sindresorhus

This comment has been minimized.

@LitoMore

This comment has been minimized.

@sindresorhus

This comment has been minimized.

@ssh352

This comment has been minimized.

@sindresorhus sindresorhus merged commit be099f2 into sindresorhus:master Jun 20, 2019
@sindresorhus
Copy link
Owner

This looks good to me now. @bricewge, Thanks for contributing 🙌

@sindresorhus
Copy link
Owner

It's out now: https://twitter.com/sindresorhus/status/1141729038068641797 🎉

@dcastil
Copy link

dcastil commented Jun 20, 2019

Huge thanks for this! Huge win for accessibility for prompt:success / prompt:error! 😊

@jonmorton
Copy link

jonmorton commented Jun 24, 2019

@bricewge Is zsh 5.2 a new enough version for this change? I started getting prompt_pure_setup:43: bad set of key/value pairs for associative array' with this update and pure no longer works.

@jonmorton
Copy link

I can confirm that reverting this diff fixes pure on zsh 5.2. I think it'd be good to make pure work for this version because it is the current stable one used by CentOS.

@mafredri
Copy link
Collaborator

@jonmorton 5.2 is supported, this was a regression. Thanks for reporting, it's fixed in 1.10.2. Btw, I even use Pure on 4.3.17 or 5.0.2, occasionally 😛.

Btw, next time please open up a new issue as it helps with tracking 😄.

kgrz added a commit to kgrz/pure that referenced this pull request Jul 18, 2019
* upstream/master: (25 commits)
  Fix incorrect color name in the readme (sindresorhus#482)
  1.10.3
  Fix username prompt expansion
  1.10.2
  Bump version number in pure state
  Fix bad set of key/value pairs on old versions of ZSH
  1.10.1
  Suppress warning of WARN_CREATE_GLOBAL option (sindresorhus#479)
  1.10.0
  Update the zsh-async version to reflect the code
  Improve code comments
  Avoid performing prompt reset in zle-line-finish hook (sindresorhus#477)
  Add support for configuring colors with zstyle (sindresorhus#472)
  Improve the style of the continuation prompt (PS2) (sindresorhus#323)
  Fix username color (sindresorhus#450)
  Add `prompt_pure_system_report` for reporting issues (sindresorhus#468)
  Add pure10k to the list of ports (sindresorhus#474)
  Create funding.yml
  Add pure-pwsh to the ports section of the readme (sindresorhus#467)
  Skip grep fork, use native zsh matching (sindresorhus#459)
  ...
filipekiss added a commit to filipekiss/pure that referenced this pull request Jul 19, 2019
* upstream/master:
  Fix incorrect color name in the readme (sindresorhus#482)
  1.10.3
  Fix username prompt expansion
  1.10.2
  Bump version number in pure state
  Fix bad set of key/value pairs on old versions of ZSH
  1.10.1
  Suppress warning of WARN_CREATE_GLOBAL option (sindresorhus#479)
  1.10.0
  Update the zsh-async version to reflect the code
  Improve code comments
  Avoid performing prompt reset in zle-line-finish hook (sindresorhus#477)
  Add support for configuring colors with zstyle (sindresorhus#472)
  Improve the style of the continuation prompt (PS2) (sindresorhus#323)
  Fix username color (sindresorhus#450)
  Add `prompt_pure_system_report` for reporting issues (sindresorhus#468)
  Add pure10k to the list of ports (sindresorhus#474)
  Create funding.yml

# Conflicts:
#	package.json
#	pure.zsh
#	readme.md
kutsan pushed a commit to kutsan/pure that referenced this pull request Jun 19, 2023
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants