zsh-syntax-highlighting icon indicating copy to clipboard operation
zsh-syntax-highlighting copied to clipboard

Document how to reduce colorfulness

Open danielshahaf opened this issue 9 years ago • 9 comments

Some people find the default colorscheme too colorful (e.g., [1]).

  • [ ] Ensure the documentation on changing the colorscheme is clear and findable.
    • [ ] Ensure the use of none to clear highlighting is documented.
    • [ ] Is it clear how to determine the name of a highlight style applied to a particular input word?
  • [ ] Consider maintaining some common sets of "less colorful" schemes, either in docs/wiki or potentially as a runtime switch.

danielshahaf avatar Nov 20 '15 02:11 danielshahaf

One option: support "themes" which are specifications of colors for multiple styles. In main-highlighter.zsh, replace the setting of default styles with

. themes${$ZSH_HIGHLIGHTER_THEME:-default}.zsh

to let people set multiple colors in one shot.

(Idea by @phy1729)

danielshahaf avatar Nov 24 '15 19:11 danielshahaf

"support "themes...to let people set multiple colors in one shot."

I couldn't agree more with this! Would love it if this support existed

johnnybarrels avatar Apr 08 '20 12:04 johnnybarrels

It does, on the themes branch. Or you can set ZSH_HIGHLIGHT_STYLES by hand.

danielshahaf avatar Apr 08 '20 18:04 danielshahaf

Is it possible to clear the default styles?

nhooyr avatar May 26 '20 16:05 nhooyr

This should do it:

source /path/to/zsh-syntax-highlighting.zsh
() {
    local -a new_values; new_values=(none)
    ZSH_HIGHLIGHT_STYLES=( ${${(@k)ZSH_HIGHLIGHT_STYLES[(I)*]}:^^new_values} )
}

danielshahaf avatar May 26 '20 17:05 danielshahaf

Not sure how that works but I ended up doing this:

source_if_exists /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
typeset -A ZSH_HIGHLIGHT_STYLES # In case it doesn't exist above.
ZSH_HIGHLIGHT_STYLES=()

# Now my custom theme.
ZSH_HIGHLIGHT_STYLES[reserved-word]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[precommand]="fg=red"
ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[rc-quote]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=black"
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[redirection]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[comment]="fg=244"

Seems to work great!

nhooyr avatar May 26 '20 23:05 nhooyr

Thanks for sharing your solution!

danielshahaf avatar May 26 '20 23:05 danielshahaf

As to how what I posted works: it uses several parameter expansion flags which, in combination, have the effect of setting ZSH_HIGHLIGHT_STYLES[$k]=none for every $k which is an already-existing key of ZSH_HIGHLIGHT_STYLES. Sorry, I don't have time to post a step-by-step explanation, but the flags are documented in zshall(1) in the sections "Parameter Expansion Flags" and "Subscript Flags".

danielshahaf avatar May 26 '20 23:05 danielshahaf

As to how what I posted works: it uses several parameter expansion flags which, in combination, have the effect of setting ZSH_HIGHLIGHT_STYLES[$k]=none for every $k which is an already-existing key of ZSH_HIGHLIGHT_STYLES. Sorry, I don't have time to post a step-by-step explanation, but the flags are documented in zshall(1) in the sections "Parameter Expansion Flags" and "Subscript Flags".

Makes sense. Thanks for the description.

nhooyr avatar May 26 '20 23:05 nhooyr