aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--fish_pager.cpp2
-rw-r--r--highlight.cpp21
-rw-r--r--highlight.h7
-rw-r--r--output.cpp56
-rw-r--r--output.h2
-rw-r--r--reader.cpp3
-rw-r--r--screen.cpp5
-rw-r--r--share/functions/__fish_config_interactive.fish2
8 files changed, 59 insertions, 39 deletions
diff --git a/fish_pager.cpp b/fish_pager.cpp
index 4f9c8223..c05ae749 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 edd977a4..af8b7c9f 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<<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
diff --git a/highlight.h b/highlight.h
index f7ec8877..d6ca36b6 100644
--- a/highlight.h
+++ b/highlight.h
@@ -64,6 +64,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
for each character in buff.
@@ -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 b46cd2b1..32d4fe13 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; 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;
+ }
+ }
+ }
}
diff --git a/output.h b/output.h
index 896e40fe..6ef3869a 100644
--- a/output.h
+++ b/output.h
@@ -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
diff --git a/reader.cpp b/reader.cpp
index 382b75a2..617f1543 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -3012,6 +3012,9 @@ const wchar_t *reader_readline()
*/
case R_EXECUTE:
{
+ /* Delete any autosuggestion */
+ data->autosuggestion.clear();
+
/*
Allow backslash-escaped newlines
*/
diff --git a/screen.cpp b/screen.cpp
index 9e785d51..e74d4e8b 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 7ec8215e..3c243ee5 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