]> arthur.barton.de Git - ax-zsh.git/commitdiff
Implement FG, BG and FX arrays, compatible to OhMyZsh & spectrum
authorAlexander Barton <alex@barton.de>
Sun, 3 Feb 2019 16:50:07 +0000 (17:50 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 3 Feb 2019 16:50:07 +0000 (17:50 +0100)
We already had a "fx" array, but this should be "FX" ...

bin/axttyinfo
core/11_terminal/11_terminal.zshrc

index e40c6b86265359b3f1e00b02a4ceb0a132aa0e31..57c76c0b010dfba611f8b8bafacb3fa86ce183e0 100755 (executable)
@@ -20,22 +20,22 @@ while [[ $# -gt 0 ]]; do
        shift
 done
 
-printf "$fg[white]$fx[bold]$(hostname)$fx[no-bold] "
-printf "$fg[yellow]$(tty)$fx[reset], "
-printf "$fg[green]$fx[underline]${TERM:-?}$fx[reset] "
-printf "(${COLUMNS:-?}x${LINES:-?}); "
-printf "$fg[white]LANG=${LANG:-?}$fx[reset]"
+print -Pn -- "$fg[white]$FX[bold]$(hostname)$FX[no-bold] "
+print -Pn -- "$fg[yellow]$(tty)$FX[reset], "
+print -Pn -- "$fg[green]$FX[underline]${TERM:-?}$FX[reset] "
+print -Pn -- "(${COLUMNS:-?}x${LINES:-?}); "
+print -Pn -- "$fg[white]LANG=${LANG:-?}$FX[reset]"
 echo
 
 [[ -z "$VERBOSE" ]] && return 0
 
 check_function_result() {
        "$1"; r=$?
-       printf " - $fg[white]$1$fx[reset]() = "
+       print -Pn -- " - $fg[white]$1$FX[reset]() = "
        if [[ $r -eq 0 ]]; then
-               echo "$fg[green]yes$fx[reset]"
+               print -P -- "$fg[green]yes$FX[reset]"
        else
-               echo "$fg[red]NO$fx[reset]"
+               print -P -- "$fg[red]NO$FX[reset]"
        fi
        return $r
 }
index 6d4c9880e2d992b82960dfaeecd39433d76507ec..4259b23af4535ce93f79984d49eaf79afb8f28c2 100644 (file)
@@ -139,19 +139,43 @@ axzsh_is_dumb_terminal && return 0
 autoload -Uz colors
 colors
 
+# Foreground (FG) and background (BG) colors.
+typeset -Ag FG BG
+for color in {000..255}; do
+       FG[$color]="%{\e[38;5;${color}m%}"
+       BG[$color]="%{\e[48;5;${color}m%}"
+done
+
 # Text effects (FX)
 
-typeset -Ag fx
-fx=(
-       reset           "\e[00m"
-       bold            "\e[01m"
-       no-bold         "\e[22m"
-       italic          "\e[03m"
-       no-italic       "\e[23m"
-       underline       "\e[04m"
-       no-underline    "\e[24m"
-       blink           "\e[05m"
-       no-blink        "\e[25m"
-       reverse         "\e[07m"
-       no-reverse      "\e[27m"
+typeset -Ag FX
+FX=(
+       reset     "%{\e[00m%}"
+       bold      "%{\e[01m%}"   no-bold      "%{\e[22m%}"
+       italic    "%{\e[03m%}"   no-italic    "%{\e[23m%}"
+       underline "%{\e[04m%}"   no-underline "%{\e[24m%}"
+       blink     "%{\e[05m%}"   no-blink     "%{\e[25m%}"
+       reverse   "%{\e[07m%}"   no-reverse   "%{\e[27m%}"
 )
+
+ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-The quick brown fox jumps over the lazy dog}
+
+# Show all 256 foreground colors with color number
+function spectrum_ls() {
+       for code in {000..255}; do
+               print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
+       done
+}
+
+# Show all 256 background colors with color number
+function spectrum_bls() {
+       for code in {000..255}; do
+               print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
+       done
+}
+
+# NOTE for FG, BG and FX arrays, and spectrum_ls() and spectrum_bls() functions:
+# Based on a script to make using 256 colors in zsh less painful, written by
+# P.C. Shyamshankar <sykora@lucentbeing.com>.
+# Copied from OhMyZsh https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/spectrum.zsh
+# which was copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ :-)