diff --git a/fish_pager.cpp b/fish_pager.cpp index 4f9c8223d..c05ae749c 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -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 ); } /** diff --git a/highlight.cpp b/highlight.cpp index edd977a40..af8b7c9fd 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -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< (1< %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 diff --git a/highlight.h b/highlight.h index f7ec88770..d6ca36b67 100644 --- a/highlight.h +++ b/highlight.h @@ -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 diff --git a/output.cpp b/output.cpp index b46cd2b1a..32d4fe133 100644 --- a/output.cpp +++ b/output.cpp @@ -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; iautosuggestion.clear(); + /* Allow backslash-escaped newlines */ diff --git a/screen.cpp b/screen.cpp index 9e785d510..e74d4e8be 100644 --- a/screen.cpp +++ b/screen.cpp @@ -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 ); diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 7ec8215ed..3c243ee51 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -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