From 331adc4a69ab7e96a41e4cc970893c6d913321ed Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sun, 22 Mar 2026 02:39:11 -0500 Subject: [PATCH] spectrum: optimize ANSI color initialization loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split the single loop that initializes both named ANSI colors (0–7) and the remaining 256-color indices into two separate loops. The first loop sets both numeric and name keys for the named ANSI colors without per-iteration checks, and the second loop sets only numeric keys for the remaining indices. --- modules/spectrum/init.zsh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/spectrum/init.zsh b/modules/spectrum/init.zsh index 37b7d7b..be8c9fc 100644 --- a/modules/spectrum/init.zsh +++ b/modules/spectrum/init.zsh @@ -56,14 +56,18 @@ FX=( FG[none]="$FX[none]" BG[none]="$FX[none]" colors=(black red green yellow blue magenta cyan white) -for color in {0..255}; do - if (( $color >= 0 )) && (( $color < $#colors )); then - index=$(( $color + 1 )) - FG[$colors[$index]]="\e[38;5;${color}m" - BG[$colors[$index]]="\e[48;5;${color}m" - fi +# Named ANSI colors (0–7) have both numeric and name keys. +for color in {0..7}; do + FG[$colors[color+1]]="\e[38;5;${color}m" + BG[$colors[color+1]]="\e[48;5;${color}m" FG[$color]="\e[38;5;${color}m" BG[$color]="\e[48;5;${color}m" done -unset color{s,} index + +# Remaining 256-color indices have only numeric keys. +for color in {8..255}; do + FG[$color]="\e[38;5;${color}m" + BG[$color]="\e[48;5;${color}m" +done +unset color{s,}