oh-my-zsh themes don't show properly (background stays white)

后端 未结 3 1495
误落风尘
误落风尘 2020-12-23 15:14

I am trying to figure out why my oh-my-zsh themes don\'t work properly. The colors show up properly, but background stays white (with black text). below is my /.zshrc file

相关标签:
3条回答
  • 2020-12-23 15:23

    Like said in the answer above it is "You need to change the terminal emulator color settings:"

    I don't find any reason changing terminal app, the easiest way is only changing the theme to one of the available themes in the link below, you can find one that suits to oh-my-zsh themes.

    osx-terminal-themes

    0 讨论(0)
  • 2020-12-23 15:37

    Short answer: no, zsh can't help you here. You need to change the terminal emulator color settings, not the zsh settings.

    This is what you're currently seeing:

    What you're seeing

    and this is what you're expecting to see:

    The RobbyRussell Theme

    This is the line that produces this prompt:

    PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c 
    %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
    

    The Z-Shell does have some foreground, background settings you can use in the PROMPT - that's what the fg_bold means (foreground to bold). You can replace this with bg_ for background, and omit the bold to use a non-bold font.

    For example, we can set the background of the PROMPT to green by adding %{bg[green]%}:

    PROMPT='%{$bg[green]%}%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c 
    %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
    

    This results in:

    Green background in the prompt

    However, this more than likely is not what you want. Note several things:

    1. The bg[green] does not extend to the edge of the terminal window - the PROMPT settings only work where the line is drawn.
    2. The background color is reset to 'default' at the end of the prompt - that's done by %{$reset_color%} (necessary to change the foreground color to default). Getting a consistant, whole-line background color gets messy quickly.

    How the colors work

    Roughly (I could be wrong in details, but the overall gist is correct, I believe): the shell you use sends a color code to the terminal emulator. The terminal emulator is responsible for interpreting that color code, and displaying it on the screen. This means there are two settings you can fiddle with:

    1. The shell color settings. That's what you're doing in your zshrc. Primiarily, this allows for consistency - you can say "Display this bit of the prompt in the same $COLOR as that bit of the prompt". This doesn't mean the user will see the prompt in $COLOR; $COLOR is a label, not much more.
    2. The displayed color settings. That's where you set the preferred font, background, text color, etc. It's where you can say "display everything the shell says is $COLOR_1 as red, $COLOR_2 as green", etc.

    There are 16 colors you can use in an ANSI terminal, which may-or-may-not be displayed correctly. Check this table for some common terminal colors, and note the differences displayed between them!

    Fixing your colors

    If you're using Terminal.app (on OS X, I'd recommend iTerm2), open the preferences for Terminal (command+,), and select "Settings". There's a bunch of "profiles" you can choose from - to emulate the robbyrussell screenshot above, you'd want to fiddle with the colors a little. "Homebrew" is pretty close, but has different "text" colors (green instead of white).

    [Here is the robbyrussell zsh theme with the Homebrew Terminal.app profile:

    Robby Russel <code>zsh</code> theme with <code>Homebrew</code> Terminal.app profile

    If you'd like a good, pre-set, easy-on-the-eyes color scheme, check out Solarized.

    0 讨论(0)
  • 2020-12-23 15:41

    For me the fix was found in a preferences panel where I had to deselect which was overriding the theme...

    I'm using gnome-terminal on an instance of Red Hat.

    Found Under: Terminal -> Preferences -> Unnamed -> Colors -> Use colors from system theme

    (took me much too long to realize that...)

    0 讨论(0)
提交回复
热议问题