mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Add support for bold highligting
darcs-hash:20060527133930-ac50b-515d0887567c0e89fdfe10fe8310d6ebb4485974.gz
This commit is contained in:
parent
6bdb0cde8b
commit
bffff77d17
5 changed files with 80 additions and 36 deletions
11
common.h
11
common.h
|
@ -20,17 +20,6 @@
|
|||
*/
|
||||
#define MAX_UTF8_BYTES 6
|
||||
|
||||
/**
|
||||
Color code for set_color. Does not update the color.
|
||||
*/
|
||||
|
||||
#define FISH_COLOR_IGNORE -1
|
||||
|
||||
/**
|
||||
Color code for set_color. Sets the default color.
|
||||
*/
|
||||
#define FISH_COLOR_RESET -2
|
||||
|
||||
/**
|
||||
This is in the unicode private use area.
|
||||
*/
|
||||
|
|
|
@ -68,11 +68,11 @@ end
|
|||
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 fish_color_comment red
|
||||
set_default fish_color_error red --bold
|
||||
set_default fish_color_escape cyan
|
||||
set_default fish_color_operator cyan
|
||||
set_default fish_color_quote blue
|
||||
set_default fish_color_quote brown
|
||||
|
||||
set_default fish_color_cwd green
|
||||
|
||||
|
|
88
output.c
88
output.c
|
@ -128,9 +128,20 @@ void set_color( int c, int c2 )
|
|||
{
|
||||
static int last_color = FISH_COLOR_NORMAL;
|
||||
static int last_color2 = FISH_COLOR_NORMAL;
|
||||
static int was_bold=0;
|
||||
int bg_set=0, last_bg_set=0;
|
||||
char *fg = 0, *bg=0;
|
||||
|
||||
int is_bold = 0;
|
||||
|
||||
is_bold |= (c&FISH_COLOR_BOLD)!=0;
|
||||
is_bold |= (c2&FISH_COLOR_BOLD)!=0;
|
||||
|
||||
// debug( 1, L"WOO %d %d %d", is_bold, c&FISH_COLOR_BOLD,c2&FISH_COLOR_BOLD);
|
||||
|
||||
c = c&(~FISH_COLOR_BOLD);
|
||||
c2 = c2&(~FISH_COLOR_BOLD);
|
||||
|
||||
if( (set_a_foreground != 0) && (strlen( set_a_foreground) != 0 ) )
|
||||
{
|
||||
fg = set_a_foreground;
|
||||
|
@ -145,14 +156,31 @@ void set_color( int c, int c2 )
|
|||
if( (c == FISH_COLOR_RESET) || (c2 == FISH_COLOR_RESET))
|
||||
{
|
||||
c = c2 = FISH_COLOR_NORMAL;
|
||||
was_bold=0;
|
||||
if( fg )
|
||||
{
|
||||
/*
|
||||
If we exit attibute mode, we must first set a color, or
|
||||
previously coloured text might lose it's
|
||||
color. Terminals are weird...
|
||||
*/
|
||||
writembs( tparm( fg, 0 ) );
|
||||
}
|
||||
writembs( exit_attribute_mode );
|
||||
return;
|
||||
}
|
||||
|
||||
if( was_bold && !is_bold )
|
||||
{
|
||||
/*
|
||||
Only way to exit bold mode is a reset of all attributes.
|
||||
*/
|
||||
writembs( exit_attribute_mode );
|
||||
last_color = FISH_COLOR_NORMAL;
|
||||
last_color2 = FISH_COLOR_NORMAL;
|
||||
was_bold=0;
|
||||
}
|
||||
|
||||
if( last_color2 != FISH_COLOR_NORMAL &&
|
||||
last_color2 != FISH_COLOR_RESET &&
|
||||
last_color2 != FISH_COLOR_IGNORE )
|
||||
|
@ -164,7 +192,6 @@ void set_color( int c, int c2 )
|
|||
}
|
||||
|
||||
if( c2 != FISH_COLOR_NORMAL &&
|
||||
c2 != FISH_COLOR_RESET &&
|
||||
c2 != FISH_COLOR_IGNORE )
|
||||
{
|
||||
/*
|
||||
|
@ -180,7 +207,8 @@ void set_color( int c, int c2 )
|
|||
{
|
||||
/*
|
||||
Background color changed and is set, so we enter bold
|
||||
mode to make reading easier
|
||||
mode to make reading easier. This means bold mode is
|
||||
_always_ on when the background color is set.
|
||||
*/
|
||||
writembs( enter_bold_mode );
|
||||
}
|
||||
|
@ -252,8 +280,21 @@ void set_color( int c, int c2 )
|
|||
last_color2 = c2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Lastly, we set bold mode correctly
|
||||
*/
|
||||
if( (enter_bold_mode != 0) && (strlen(enter_bold_mode) > 0) && !bg_set )
|
||||
{
|
||||
if( is_bold && !was_bold )
|
||||
{
|
||||
writembs( tparm( enter_bold_mode ) );
|
||||
}
|
||||
was_bold = is_bold;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
perm_left_cursor and parm_right_cursor don't seem to be properly
|
||||
emulated by many terminal emulators, so we only use plain
|
||||
|
@ -475,23 +516,34 @@ int writespace( int c )
|
|||
|
||||
int output_color_code( const wchar_t *val )
|
||||
{
|
||||
int i, color=-1;
|
||||
int j, i, color=FISH_COLOR_NORMAL;
|
||||
array_list_t el;
|
||||
int is_bold=0;
|
||||
|
||||
for( i=0; i<COLORS; i++ )
|
||||
{
|
||||
if( wcscasecmp( col[i], val ) == 0 )
|
||||
{
|
||||
color = col_idx[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( color >= 0 )
|
||||
{
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !val )
|
||||
return FISH_COLOR_NORMAL;
|
||||
|
||||
al_init( &el );
|
||||
expand_variable_array( val, &el );
|
||||
|
||||
for( j=0; j<al_get_count( &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 |= wcscmp( next, L"-b" ) == 0;
|
||||
|
||||
for( i=0; i<COLORS; i++ )
|
||||
{
|
||||
if( wcscasecmp( col[i], next ) == 0 )
|
||||
{
|
||||
color = col_idx[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return color | (is_bold?FISH_COLOR_BOLD:0);
|
||||
|
||||
}
|
||||
|
|
7
output.h
7
output.h
|
@ -41,10 +41,13 @@ enum
|
|||
FISH_COLOR_CYAN,
|
||||
FISH_COLOR_WHITE,
|
||||
/** The default fg color of the terminal */
|
||||
FISH_COLOR_NORMAL
|
||||
FISH_COLOR_NORMAL,
|
||||
FISH_COLOR_IGNORE,
|
||||
FISH_COLOR_RESET
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
#define FISH_COLOR_BOLD 0x80
|
||||
|
||||
/**
|
||||
Sets the fg and bg color. May be called as often as you like, since
|
||||
|
|
4
reader.c
4
reader.c
|
@ -917,7 +917,7 @@ void repaint()
|
|||
if( steps )
|
||||
move_cursor( -steps );
|
||||
|
||||
set_color( FISH_COLOR_NORMAL, -1 );
|
||||
set_color( FISH_COLOR_NORMAL, FISH_COLOR_IGNORE );
|
||||
reader_save_status();
|
||||
}
|
||||
|
||||
|
@ -1144,7 +1144,7 @@ static int insert_char( int c )
|
|||
}
|
||||
else
|
||||
writech(c);
|
||||
set_color( FISH_COLOR_NORMAL, -1 );
|
||||
set_color( FISH_COLOR_NORMAL, FISH_COLOR_IGNORE );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue