Added autosuggestion color variable fish_color_autosuggestion

Fixed that nasty bug where fish would apply a color to both the foreground and background (yuck)
This commit is contained in:
ridiculousfish 2012-02-06 20:14:19 -08:00
parent e5b34d5cd5
commit 382ffe9b6a
8 changed files with 59 additions and 39 deletions

View file

@ -221,7 +221,7 @@ static int get_color( int highlight )
return FISH_COLOR_NORMAL;
}
return output_color_code( val );
return output_color_code( val, false );
}
/**

View file

@ -48,7 +48,7 @@ static void highlight_universal_internal( const wchar_t * buff,
/**
The environment variables used to specify the color of different tokens.
*/
static const wchar_t *highlight_var[] =
static const wchar_t * const highlight_var[] =
{
L"fish_color_normal",
L"fish_color_error",
@ -62,9 +62,9 @@ static const wchar_t *highlight_var[] =
L"fish_color_escape",
L"fish_color_quote",
L"fish_color_redirection",
L"fish_color_valid_path"
}
;
L"fish_color_valid_path",
L"fish_color_autosuggestion"
};
/**
Tests if the specified string is the prefix of any valid path in the system.
@ -170,7 +170,7 @@ static bool is_potential_path( const wcstring &cpath )
int highlight_get_color( int highlight )
int highlight_get_color( int highlight, bool is_background )
{
size_t i;
int idx=0;
@ -178,10 +178,9 @@ int highlight_get_color( int highlight )
if( highlight < 0 )
return FISH_COLOR_NORMAL;
if( highlight >= (1<<VAR_COUNT) )
if( highlight > (1<<VAR_COUNT) )
return FISH_COLOR_NORMAL;
for( i=0; i<(VAR_COUNT-1); i++ )
for( i=0; i<VAR_COUNT; i++ )
{
if( highlight & (1<<i ))
{
@ -189,7 +188,7 @@ int highlight_get_color( int highlight )
break;
}
}
env_var_t val_wstr = env_get_string( highlight_var[idx]);
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
@ -198,14 +197,14 @@ int highlight_get_color( int highlight )
val_wstr = env_get_string( highlight_var[0]);
if( ! val_wstr.missing() )
result = output_color_code( val_wstr.c_str() );
result = output_color_code( val_wstr, is_background );
if( highlight & HIGHLIGHT_VALID_PATH )
{
env_var_t val2_wstr = env_get_string( L"fish_color_valid_path" );
const wchar_t *val2 = val2_wstr.missing() ? NULL : val2_wstr.c_str();
int result2 = output_color_code( val2 );
int result2 = output_color_code( val2, is_background );
if( result == FISH_COLOR_NORMAL )
result = result2;
else

View file

@ -63,6 +63,11 @@
*/
#define HIGHLIGHT_VALID_PATH 0x1000
/**
Internal value representing highlighting an autosuggestion
*/
#define HIGHLIGHT_AUTOSUGGESTION 0x2000
/**
Perform syntax highlighting for the shell commands in buff. The result is
stored in the color array as a color_code from the HIGHLIGHT_ enum
@ -97,6 +102,6 @@ void highlight_universal( const wchar_t *buff, int *color, int pos, array_list_t
call to highlight_get_color( HIGHLIGHT_ERROR) will return
FISH_COLOR_RED.
*/
int highlight_get_color( int highlight );
int highlight_get_color( int highlight, bool is_background );
#endif

View file

@ -149,7 +149,9 @@ int (*output_get_writer())(char)
void set_color( int c, int c2 )
{
static int last_color = FISH_COLOR_NORMAL;
ASSERT_IS_MAIN_THREAD();
static int last_color = FISH_COLOR_NORMAL;
static int last_color2 = FISH_COLOR_NORMAL;
static int was_bold=0;
static int was_underline=0;
@ -546,37 +548,47 @@ int write_escaped_str( const wchar_t *str, int max_len )
}
int output_color_code( const wchar_t *val )
{
int output_color_code( const wcstring &val, bool is_background ) {
size_t i;
int color=FISH_COLOR_NORMAL;
int is_bold=0;
int is_underline=0;
if( !val )
if (val.empty())
return FISH_COLOR_NORMAL;
wcstring_list_t el;
tokenize_variable_array2( val, el );
for(size_t j=0; j < el.size(); j++ )
{
const wchar_t *next = el.at(j).c_str();
is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
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;
for( i=0; i<COLORS; i++ )
{
if( wcscasecmp( col[i], next ) == 0 )
{
color = col_idx[i];
break;
}
}
for(size_t j=0; j < el.size(); j++ ) {
const wcstring &next = el.at(j);
wcstring color_name;
if (is_background) {
// look for something like "--background=red"
const wcstring prefix = L"--background=";
if (string_prefixes_string(prefix, next)) {
color_name = wcstring(next, prefix.size());
}
} else {
if (next == L"--bold" || next == L"-o")
is_bold = true;
else if (next == L"--underline" || next == L"-u")
is_underline = true;
else
color_name = next;
}
if (! color_name.empty()) {
for( i=0; i<COLORS; i++ )
{
if( wcscasecmp( col[i], color_name.c_str() ) == 0 )
{
color = col_idx[i];
break;
}
}
}
}

View file

@ -128,7 +128,7 @@ int write_escaped_str( const wchar_t *str, int max_len );
/**
Return the internal color code representing the specified color
*/
int output_color_code( const wchar_t *val );
int output_color_code( const wcstring &val, bool is_background );
/**
This is for writing process notification messages. Has to write to

View file

@ -3012,6 +3012,9 @@ const wchar_t *reader_readline()
*/
case R_EXECUTE:
{
/* Delete any autosuggestion */
data->autosuggestion.clear();
/*
Allow backslash-escaped newlines
*/

View file

@ -529,8 +529,9 @@ static void s_set_color( screen_t *s, buffer_t *b, int c )
output_set_writer( &s_writeb );
s_writeb_buffer = b;
set_color( highlight_get_color( c & 0xffff ),
highlight_get_color( (c>>16)&0xffff ) );
unsigned int uc = (unsigned int)c;
set_color( highlight_get_color( uc & 0xffff, false ),
highlight_get_color( (uc>>16)&0xffff, true ) );
output_set_writer( writer_old );

View file

@ -113,7 +113,7 @@ function __fish_config_interactive -d "Initializations that should be performed
set_default fish_color_match cyan
# Background color for search matches
set_default fish_color_search_match purple
set_default fish_color_search_match --background=purple
# Pager colors
set_default fish_pager_color_prefix cyan