Zsh can print colored status text without hard-coding raw escape bytes in every command. Prompt-style color escapes keep short terminal messages readable and make it clear when a script is reporting a ready, warning, or error state.

The print builtin expands prompt sequences when it runs with -P. Adding -r keeps ordinary backslash text in the message from being treated as a print escape. Foreground color starts with %F{color} and returns to the terminal's default foreground with %f, so the color stays attached to the label instead of leaking into the rest of the line.

The same pattern fits interactive helpers and small Zsh scripts that need simple status output. It depends on terminal color support, and redirected output will still contain escape sequences unless the script adds a separate no-color path.

Steps to color output in Zsh:

  1. Open a Zsh terminal or the script that should print colored status messages.
  2. Print one colored line with prompt expansion.
    $ print -rP -- '%F{green}READY%f deployment check passed'
    READY deployment check passed

    The word READY appears green in a color-capable terminal. The -- separator prevents later message text that begins with a hyphen from being parsed as another print option.

  3. Create a small script with reset-wrapped labels.
    status-colors.zsh
    #!/usr/bin/env zsh
    print -rP -- '%F{green}READY%f deployment check passed'
    print -rP -- '%F{yellow}WARN%f review disk space'
    print -rP -- '%F{red}ERROR%f release blocked'

    green, yellow, and red are named foreground colors. Keep %f after the colored label so normal message text returns to the terminal's default foreground color.

  4. Check the script syntax.
    $ zsh -n status-colors.zsh

    No output from zsh -n means Zsh parsed the script without finding a syntax error.

  5. Run the script in a color terminal.
    $ zsh status-colors.zsh
    READY deployment check passed
    WARN review disk space
    ERROR release blocked

    The labels appear green, yellow, and red. The message text after each label should use the terminal's normal foreground color.

  6. Use a background color only when the label must stand apart from normal output.
    $ print -rP -- '%K{red}%F{white} ERROR %f%k release blocked'
     ERROR  release blocked

    %K{red} starts a red background, %k resets the background, and %f resets the foreground.

  7. Keep colored output out of plain-text logs and machine-readable output.

    ANSI color sequences are bytes in the output stream. Disable color when another command, log collector, or parser expects plain text.