diff --git a/doc_src/set_color.txt b/doc_src/set_color.txt index 742a69fc2..02c5ad231 100644 --- a/doc_src/set_color.txt +++ b/doc_src/set_color.txt @@ -10,10 +10,11 @@ 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 -c, \c --print-colors Prints a list of all valid color names - \c -h, \c --help Display help message and exit +- \c -o, \c --bold Set bold or extra bright mode +- \c -u, \c --underline Set underlined mode - \c -v, \c --version Display version and exit @@ -25,3 +26,6 @@ color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. +Not all terminal emulators support all these features. This is not a +bug in set_color but a missing feature in the terminal emulator. + diff --git a/output.c b/output.c index 4a801eb42..f2183ed26 100644 --- a/output.c +++ b/output.c @@ -560,7 +560,7 @@ int output_color_code( const wchar_t *val ) wchar_t *next = (wchar_t *)al_get( &el, j ); is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3; - is_bold |= wcscmp( next, L"-b" ) == 0; + is_bold |= wcscmp( next, L"-o" ) == 0; is_underline |= (wcsncmp( next, L"--underline", wcslen(next) ) == 0 ) && wcslen(next)>=3; is_underline |= wcscmp( next, L"-u" ) == 0; diff --git a/set_color.c b/set_color.c index f762c64dc..b5873bc7a 100644 --- a/set_color.c +++ b/set_color.c @@ -36,6 +36,8 @@ #include #endif +#include "fallback.h" + /* Small utility for setting the color. Usage: set_color COLOR @@ -52,7 +54,7 @@ /** Getopt short switches for set_color */ -#define GETOPT_STRING "b:hvoc" +#define GETOPT_STRING "b:hvocu" #if HAVE_GETTEXT #define _(string) gettext(string) @@ -152,9 +154,9 @@ int main( int argc, char **argv ) char *fgcolor=0; int fg, bg; int bold=0; - - - + int underline=0; + char *bg_seq, *fg_seq; + while( 1 ) { #ifdef HAVE_GETOPT_LONG @@ -173,6 +175,10 @@ int main( int argc, char **argv ) "bold", no_argument, 0, 'o' } , + { + "underline", no_argument, 0, 'u' + } + , { "version", no_argument, 0, 'v' } @@ -218,6 +224,10 @@ int main( int argc, char **argv ) bold=1; break; + case 'u': + underline=1; + break; + case 'v': check_locale_init(); fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION ); @@ -251,7 +261,7 @@ int main( int argc, char **argv ) return 1; } - if( !fgcolor && !bgcolor && !bold ) + if( !fgcolor && !bgcolor && !bold && !underline ) { check_locale_init(); fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR ); @@ -277,16 +287,28 @@ int main( int argc, char **argv ) setupterm( 0, STDOUT_FILENO, 0); + fg_seq = set_a_foreground?set_a_foreground:set_foreground; + bg_seq = set_a_background?set_a_background:set_background; + + if( bold ) { - putp( enter_bold_mode ); + if( enter_bold_mode ) + putp( enter_bold_mode ); + } + + if( underline ) + { + if( enter_underline_mode ) + putp( enter_underline_mode ); } if( bgcolor ) { if( bg == 8 ) { - putp( tparm( set_a_background, 0) ); + if( bg_seq ) + putp( tparm( bg_seq, 0) ); putp( tparm(exit_attribute_mode) ); } } @@ -295,12 +317,14 @@ int main( int argc, char **argv ) { if( fg == 8 ) { - putp( tparm( set_a_foreground, 0) ); + if( fg_seq ) + putp( tparm( fg_seq, 0) ); putp( tparm(exit_attribute_mode) ); } else { - putp( tparm( set_a_foreground, fg) ); + if( fg_seq ) + putp( tparm( fg_seq, fg) ); } } @@ -308,8 +332,11 @@ int main( int argc, char **argv ) { if( bg != 8 ) { - putp( tparm( set_a_background, bg) ); + if( bg_seq ) + putp( tparm( bg_seq, bg) ); } } + del_curterm( cur_term ); + } diff --git a/share/completions/set_color.fish b/share/completions/set_color.fish index 4a603689b..d62e8a7de 100644 --- a/share/completions/set_color.fish +++ b/share/completions/set_color.fish @@ -1,3 +1,8 @@ complete -c set_color -x -d (N_ "Color") -a '(set_color --print-colors)' complete -c set_color -s b -l background -x -a '(set_color --print-colors)' -d (N_ "Change background color") complete -c set_color -s o -l bold -d (N_ 'Make font bold') +complete -c set_color -s u -l underline -d (N_ 'Underline text') +complete -c set_color -s v -l version -d (N_ 'Display version and exit') +complete -c set_color -s h -l help -d (N_ 'Display help and exit') +complete -c set_color -s c -l print-colors -d (N_ 'Print a list of all accepted color names') +