Powerlevel10k: Adding support for 24-bit colors

Created on 30 Apr 2019  路  1Comment  路  Source: romkatv/powerlevel10k

Most helpful comment

In order to use true color with Powerlevel10k you need ZSH >= 5.7 and a terminal that supports true color. Here's how you can check whether you are covered.

if autoload -U is-at-least && is-at-least 5.7; then
  echo "ZSH $ZSH_VERSION: supports true color"
else
  echo "ZSH $ZSH_VERSION: does not support true color"
fi

if [[ $COLORTERM == (24bit|truecolor) || ${terminfo[colors]} -eq 16777216 ]]; then
  echo "Terminal supports true color"
else
  echo "Terminal does not support true color"
fi

To use true color with Powerlevel10k, use #ffffff format when specifying colors.

POWERLEVEL9K_TIME_FOREGROUND='red'      # by name (type `getColorCode foreground` to list all)
POWERLEVEL9K_TIME_BACKGROUND='001'      # by decimal code (usually 001 to 256)
POWERLEVEL9K_TIME_BACKGROUND='#ff0000'  # by hex code (#000000 to #ffffff)

In order to be able to use the same configuration from a terminal without true color support, add this to your ~/.zshrc:

if [[ $COLORTERM != (24bit|truecolor) && ${terminfo[colors]} -ne 16777216 ]]; then
  zmodload zsh/nearcolor
fi

When using a true color terminal, #ffffff will render as true color. When on an older terminal, it'll render as the closest available color. Neat!

>All comments

In order to use true color with Powerlevel10k you need ZSH >= 5.7 and a terminal that supports true color. Here's how you can check whether you are covered.

if autoload -U is-at-least && is-at-least 5.7; then
  echo "ZSH $ZSH_VERSION: supports true color"
else
  echo "ZSH $ZSH_VERSION: does not support true color"
fi

if [[ $COLORTERM == (24bit|truecolor) || ${terminfo[colors]} -eq 16777216 ]]; then
  echo "Terminal supports true color"
else
  echo "Terminal does not support true color"
fi

To use true color with Powerlevel10k, use #ffffff format when specifying colors.

POWERLEVEL9K_TIME_FOREGROUND='red'      # by name (type `getColorCode foreground` to list all)
POWERLEVEL9K_TIME_BACKGROUND='001'      # by decimal code (usually 001 to 256)
POWERLEVEL9K_TIME_BACKGROUND='#ff0000'  # by hex code (#000000 to #ffffff)

In order to be able to use the same configuration from a terminal without true color support, add this to your ~/.zshrc:

if [[ $COLORTERM != (24bit|truecolor) && ${terminfo[colors]} -ne 16777216 ]]; then
  zmodload zsh/nearcolor
fi

When using a true color terminal, #ffffff will render as true color. When on an older terminal, it'll render as the closest available color. Neat!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bwoodruff picture bwoodruff  路  6Comments

gigglearrows picture gigglearrows  路  4Comments

gibfahn picture gibfahn  路  5Comments

Mystic8b picture Mystic8b  路  4Comments

romkatv picture romkatv  路  5Comments