mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Update the set_color command: Add underline support, make the command a bit more rubust to missing ferminal features, and update documentation and completions
darcs-hash:20060615134915-ac50b-de1092e56490bbf1c58cc3422c239a2997645b6b.gz
This commit is contained in:
parent
eed8b61a9e
commit
94d1322fc1
@ -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,
|
COLOR is one of black, red, green, brown, yellow, blue, magenta,
|
||||||
purple, cyan, white and normal.
|
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 -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 -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
|
- \c -v, \c --version Display version and exit
|
||||||
|
|
||||||
|
|
||||||
@ -25,3 +26,6 @@ color set. On such terminals, <code>set_color white</code> will result
|
|||||||
in a grey font color, while <code>set_color --bold white</code> will
|
in a grey font color, while <code>set_color --bold white</code> will
|
||||||
result in a white font color.
|
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.
|
||||||
|
|
||||||
|
2
output.c
2
output.c
@ -560,7 +560,7 @@ int output_color_code( const wchar_t *val )
|
|||||||
wchar_t *next = (wchar_t *)al_get( &el, j );
|
wchar_t *next = (wchar_t *)al_get( &el, j );
|
||||||
|
|
||||||
is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
|
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 |= (wcsncmp( next, L"--underline", wcslen(next) ) == 0 ) && wcslen(next)>=3;
|
||||||
is_underline |= wcscmp( next, L"-u" ) == 0;
|
is_underline |= wcscmp( next, L"-u" ) == 0;
|
||||||
|
47
set_color.c
47
set_color.c
@ -36,6 +36,8 @@
|
|||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "fallback.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Small utility for setting the color.
|
Small utility for setting the color.
|
||||||
Usage: set_color COLOR
|
Usage: set_color COLOR
|
||||||
@ -52,7 +54,7 @@
|
|||||||
/**
|
/**
|
||||||
Getopt short switches for set_color
|
Getopt short switches for set_color
|
||||||
*/
|
*/
|
||||||
#define GETOPT_STRING "b:hvoc"
|
#define GETOPT_STRING "b:hvocu"
|
||||||
|
|
||||||
#if HAVE_GETTEXT
|
#if HAVE_GETTEXT
|
||||||
#define _(string) gettext(string)
|
#define _(string) gettext(string)
|
||||||
@ -152,9 +154,9 @@ int main( int argc, char **argv )
|
|||||||
char *fgcolor=0;
|
char *fgcolor=0;
|
||||||
int fg, bg;
|
int fg, bg;
|
||||||
int bold=0;
|
int bold=0;
|
||||||
|
int underline=0;
|
||||||
|
char *bg_seq, *fg_seq;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETOPT_LONG
|
#ifdef HAVE_GETOPT_LONG
|
||||||
@ -173,6 +175,10 @@ int main( int argc, char **argv )
|
|||||||
"bold", no_argument, 0, 'o'
|
"bold", no_argument, 0, 'o'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
{
|
||||||
|
"underline", no_argument, 0, 'u'
|
||||||
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
@ -218,6 +224,10 @@ int main( int argc, char **argv )
|
|||||||
bold=1;
|
bold=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
underline=1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
check_locale_init();
|
check_locale_init();
|
||||||
fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION );
|
fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION );
|
||||||
@ -251,7 +261,7 @@ int main( int argc, char **argv )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !fgcolor && !bgcolor && !bold )
|
if( !fgcolor && !bgcolor && !bold && !underline )
|
||||||
{
|
{
|
||||||
check_locale_init();
|
check_locale_init();
|
||||||
fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR );
|
fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR );
|
||||||
@ -277,16 +287,28 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
setupterm( 0, STDOUT_FILENO, 0);
|
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 )
|
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( bgcolor )
|
||||||
{
|
{
|
||||||
if( bg == 8 )
|
if( bg == 8 )
|
||||||
{
|
{
|
||||||
putp( tparm( set_a_background, 0) );
|
if( bg_seq )
|
||||||
|
putp( tparm( bg_seq, 0) );
|
||||||
putp( tparm(exit_attribute_mode) );
|
putp( tparm(exit_attribute_mode) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,12 +317,14 @@ int main( int argc, char **argv )
|
|||||||
{
|
{
|
||||||
if( fg == 8 )
|
if( fg == 8 )
|
||||||
{
|
{
|
||||||
putp( tparm( set_a_foreground, 0) );
|
if( fg_seq )
|
||||||
|
putp( tparm( fg_seq, 0) );
|
||||||
putp( tparm(exit_attribute_mode) );
|
putp( tparm(exit_attribute_mode) );
|
||||||
}
|
}
|
||||||
else
|
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 )
|
if( bg != 8 )
|
||||||
{
|
{
|
||||||
putp( tparm( set_a_background, bg) );
|
if( bg_seq )
|
||||||
|
putp( tparm( bg_seq, bg) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
del_curterm( cur_term );
|
del_curterm( cur_term );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
complete -c set_color -x -d (N_ "Color") -a '(set_color --print-colors)'
|
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 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 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')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user