From 48afe8062ed72108a7928bd656ce465cc55bc676 Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 25 Oct 2005 03:51:08 +1000 Subject: [PATCH] Make sure fish color settings are valid colors darcs-hash:20051024175108-ac50b-3abfbd8b5974c7a3a53bc70d425d41dd1295da02.gz --- doc_src/set_color.txt | 2 ++ init/completions/set.fish | 2 +- init/completions/set_color.fish | 6 ++---- init/fish_interactive.fish | 35 +++++++++++++++++++-------------- set_color.c | 23 +++++++++++++++++++--- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/doc_src/set_color.txt b/doc_src/set_color.txt index 2c7e84b7b..b1f6879ee 100644 --- a/doc_src/set_color.txt +++ b/doc_src/set_color.txt @@ -10,11 +10,13 @@ Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. +- \c -c, \c --print-colors Prints a list of all valid color names - \c -b, \c --background Set the background color - \c -o, \c --bold Set bold or extra bright mode - \c -h, \c --help Display help message and exit - \c -v, \c --version Display version and exit + Calling set_color normal will set the terminal color to whatever is the default color of the terminal. diff --git a/init/completions/set.fish b/init/completions/set.fish index 183d0932e..d1bee0fe5 100644 --- a/init/completions/set.fish +++ b/init/completions/set.fish @@ -43,4 +43,4 @@ function __fish_set_is_color -d 'Test if We are specifying a color value for the end end -complete -c set -n '__fish_set_is_color' -x -a '$__fish_colors' -d Color +complete -c set -n '__fish_set_is_color' -x -a '(set_color --print-colors)' -d Color diff --git a/init/completions/set_color.fish b/init/completions/set_color.fish index fe5513419..aead79b3d 100644 --- a/init/completions/set_color.fish +++ b/init/completions/set_color.fish @@ -1,5 +1,3 @@ -set -g __fish_colors black red green brown blue magenta cyan white normal - -complete -c set_color -x -d "Color" -a '$__fish_colors' -complete -c set_color -s b -l background -x -a '$__fish_colors' -d "Change background color" +complete -c set_color -x -d "Color" -a '(set_color --print-colors)' +complete -c set_color -s b -l background -x -a '(set_color --print-colors)' -d "Change background color" complete -c set_color -s o -l bold -d 'Make font bold' diff --git a/init/fish_interactive.fish b/init/fish_interactive.fish index 70d54358f..8a6a76541 100644 --- a/init/fish_interactive.fish +++ b/init/fish_interactive.fish @@ -53,10 +53,15 @@ end # Set various color values # -function set_default -d "Set an universal variable, unless it has already been set" +function set_default_color -d "Set an universal variable, unless it has already been set. If set, verify that it is a valid color name" if not set -q $argv[1] set -U -- $argv + return end + if contains $$argv[1] (set_color --print-colors) + return + end + set -U -- $argv end function set_exported_default -d "Set an exported universal variable, unless it has already been set" @@ -67,28 +72,28 @@ end # Regular syntax highlighting colors -set_default fish_color_normal normal -set_default fish_color_command green -set_default fish_color_redirection normal -set_default fish_color_comment brown -set_default fish_color_error red +set_default_color fish_color_normal normal +set_default_color fish_color_command green +set_default_color fish_color_redirection normal +set_default_color fish_color_comment brown +set_default_color fish_color_error red -set_default fish_color_cwd green +set_default_color fish_color_cwd green # Background color for matching quotes and parenthesis -set_default fish_color_match cyan +set_default_color fish_color_match cyan # Background color for search matches -set_default fish_color_search_match purple +set_default_color fish_color_search_match purple # Pager colors -set_default fish_pager_color_prefix cyan -set_default fish_pager_color_completion normal -set_default fish_pager_color_description normal -set_default fish_pager_color_progress cyan +set_default_color fish_pager_color_prefix cyan +set_default_color fish_pager_color_completion normal +set_default_color fish_pager_color_description normal +set_default_color fish_pager_color_progress cyan # Directory history colors -set_default fish_color_history_current cyan +set_default_color fish_color_history_current cyan # @@ -115,5 +120,5 @@ if command ls --color=auto --help 1>/dev/null 2>/dev/null end -functions -e set_default +functions -e set_default_color functions -e set_exported_default diff --git a/set_color.c b/set_color.c index d0adea413..2265776e0 100644 --- a/set_color.c +++ b/set_color.c @@ -96,13 +96,22 @@ int translate_color( char *str ) } +void print_colors() +{ + int i; + for( i=0; i