aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--common.c15
-rw-r--r--common.h15
-rw-r--r--doc_src/doc.hdr2
-rw-r--r--etc/fish_interactive.fish.in2
-rw-r--r--highlight.c295
-rw-r--r--output.h2
6 files changed, 307 insertions, 24 deletions
diff --git a/common.c b/common.c
index f1108ab4..af0eab42 100644
--- a/common.c
+++ b/common.c
@@ -67,21 +67,6 @@ parts of fish.
*/
#define LOCKPOLLINTERVAL 10
-/**
- Highest legal ascii value
-*/
-#define ASCII_MAX 127u
-
-/**
- Highest legal 16-bit unicode value
-*/
-#define UCS2_MAX 0xffffu
-
-/**
- Highest legal byte value
-*/
-#define BYTE_MAX 0xffu
-
struct termios shell_modes;
int error_max=1;
diff --git a/common.h b/common.h
index 979076b2..e2a4379f 100644
--- a/common.h
+++ b/common.h
@@ -36,6 +36,21 @@
*/
#define ENCODE_DIRECT_BASE 0xf100
+/**
+ Highest legal ascii value
+*/
+#define ASCII_MAX 127u
+
+/**
+ Highest legal 16-bit unicode value
+*/
+#define UCS2_MAX 0xffffu
+
+/**
+ Highest legal byte value
+*/
+#define BYTE_MAX 0xffu
+
/**
Save the shell mode on startup so we can restore them on exit
*/
diff --git a/doc_src/doc.hdr b/doc_src/doc.hdr
index 5791d641..599e70be 100644
--- a/doc_src/doc.hdr
+++ b/doc_src/doc.hdr
@@ -752,7 +752,7 @@ certain environment variables.
- \c BROWSER, which is the users preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
- \c CDPATH, which is an array of directories in which to search for the new directory for the \c cd builtin.
-- \c fish_color_normal, \c fish_color_command, \c fish_color_substitution, \c fish_color_redirection, \c fish_color_end, \c fish_color_error, \c fish_color_param, \c fish_color_comment, \c fish_color_match, \c fish_color_search_match, \c fish_color_cwd, \c fish_pager_color_prefix, \c fish_pager_color_completion, \c fish_pager_color_description and \c fish_pager_color_progress are used to change the color of various elements in \c fish. These variables are universal, i.e. when changing them, their new value will be used by all running fish sessions. The new value will also be retained when restarting fish.
+- \c fish_color_normal, \c fish_color_command, \c fish_color_substitution, \c fish_color_redirection, \c fish_color_end, \c fish_color_error, \c fish_color_param, \c fish_color_comment, \c fish_color_match, \c fish_color_search_match, \c fish_color_operator, \c fish_color_escape, \c fish_color_cwd, \c fish_pager_color_prefix, \c fish_pager_color_completion, \c fish_pager_color_description and \c fish_pager_color_progress are used to change the color of various elements in \c fish. These variables are universal, i.e. when changing them, their new value will be used by all running fish sessions. The new value will also be retained when restarting fish.
- \c PATH, which is an array of directories in which to search for commands
- \c umask, which is the current file creation mask. The preferred way to change the umask variable is through the <a href="commands.html#umask">umask shellscript function</a>. An attempt to set umask to an invalid value will always fail.
diff --git a/etc/fish_interactive.fish.in b/etc/fish_interactive.fish.in
index 69fa1183..873d77ed 100644
--- a/etc/fish_interactive.fish.in
+++ b/etc/fish_interactive.fish.in
@@ -70,6 +70,8 @@ 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_escape cyan
+set_default fish_color_operator cyan
set_default fish_color_cwd green
diff --git a/highlight.c b/highlight.c
index 6ebcb00f..941b649e 100644
--- a/highlight.c
+++ b/highlight.c
@@ -40,7 +40,7 @@ static void highlight_universal_internal( wchar_t * buff,
/**
The environment variables used to specify the color of different tokens.
*/
-static wchar_t *hightlight_var[] =
+static wchar_t *highlight_var[] =
{
L"fish_color_normal",
L"fish_color_command",
@@ -52,24 +52,23 @@ static wchar_t *hightlight_var[] =
L"fish_color_comment",
L"fish_color_match",
L"fish_color_search_match",
- L"fish_color_pager_prefix",
- L"fish_color_pager_completion",
- L"fish_color_pager_description",
- L"fish_color_pager_progress"
+ L"fish_color_operator",
+ L"fish_color_escape"
}
;
+#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
int highlight_get_color( int highlight )
{
if( highlight < 0 )
return FISH_COLOR_NORMAL;
- if( highlight >= (12) )
+ if( highlight >= VAR_COUNT )
return FISH_COLOR_NORMAL;
- wchar_t *val = env_get( hightlight_var[highlight]);
+ wchar_t *val = env_get( highlight_var[highlight]);
if( val == 0 )
- val = env_get( hightlight_var[HIGHLIGHT_NORMAL]);
+ val = env_get( highlight_var[HIGHLIGHT_NORMAL]);
if( val == 0 )
{
@@ -79,6 +78,280 @@ int highlight_get_color( int highlight )
return output_color_code( val );
}
+static void highlight_param( const wchar_t * buff,
+ int *color,
+ int pos,
+ array_list_t *error )
+{
+
+
+ int mode = 0;
+ int in_pos, len = wcslen( buff );
+ int bracket_count=0;
+ wchar_t c;
+
+ for( in_pos=0;
+ in_pos<len;
+ in_pos++ )
+ {
+ c = buff[in_pos];
+ switch( mode )
+ {
+
+ /*
+ Mode 0 means unquoted string
+ */
+ case 0:
+ {
+ if( c == L'\\' )
+ {
+ int start_pos = in_pos;
+
+ switch( buff[++in_pos] )
+ {
+ case L'n':
+ case L'r':
+ case L't':
+ case L'b':
+ case L'e':
+ {
+ color[start_pos]=HIGHLIGHT_ESCAPE;
+ color[in_pos+1]=HIGHLIGHT_NORMAL;
+ break;
+ }
+
+ case L'u':
+ case L'U':
+ case L'x':
+ case L'X':
+ case L'0':
+ case L'1':
+ case L'2':
+ case L'3':
+ case L'4':
+ case L'5':
+ case L'6':
+ case L'7':
+ {
+ int i;
+ long long res=0;
+ int chars=2;
+ int base=16;
+
+ int byte = 0;
+ wchar_t max_val = ASCII_MAX;
+
+ switch( buff[in_pos] )
+ {
+ case L'u':
+ {
+ chars=4;
+ max_val = UCS2_MAX;
+ break;
+ }
+
+ case L'U':
+ {
+ chars=8;
+ max_val = WCHAR_MAX;
+ break;
+ }
+
+ case L'x':
+ {
+ break;
+ }
+
+ case L'X':
+ {
+ byte=1;
+ max_val = BYTE_MAX;
+ break;
+ }
+
+ default:
+ {
+ base=8;
+ chars=3;
+ in_pos--;
+ break;
+ }
+ }
+
+ for( i=0; i<chars; i++ )
+ {
+ int d = convert_digit( buff[++in_pos],base);
+
+ if( d < 0 )
+ {
+ in_pos--;
+ break;
+ }
+
+ res=(res*base)|d;
+ }
+
+ if( (res <= max_val) )
+ {
+ color[start_pos] = HIGHLIGHT_ESCAPE;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ }
+ else
+ {
+ color[start_pos] = HIGHLIGHT_ERROR;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ }
+
+ break;
+ }
+ }
+ }
+ else
+ {
+ switch( buff[in_pos]){
+ case L'~':
+ case L'%':
+ {
+ if( in_pos == 0 )
+ {
+ color[in_pos] = HIGHLIGHT_OPERATOR;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ }
+ break;
+ }
+
+ case L'*':
+ case L'?':
+ case L'$':
+ {
+ color[in_pos] = HIGHLIGHT_OPERATOR;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ break;
+ }
+
+ case L'{':
+ {
+ bracket_count++;
+ break;
+ }
+
+ case L'}':
+ {
+ bracket_count--;
+ break;
+ }
+
+ case L',':
+ {
+ if( bracket_count )
+ {
+ color[in_pos] = HIGHLIGHT_OPERATOR;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ }
+
+ break;
+ }
+
+ case L'\'':
+ {
+ mode = 1;
+ break;
+ }
+
+ case L'\"':
+ {
+ mode = 2;
+ break;
+ }
+
+ }
+ }
+ break;
+ }
+
+ /*
+ Mode 1 means single quoted string, i.e 'foo'
+ */
+ case 1:
+ {
+ if( c == L'\\' )
+ {
+ int start_pos = in_pos;
+ switch( buff[++in_pos] )
+ {
+ case '\\':
+ case L'\'':
+ {
+ color[start_pos] = HIGHLIGHT_ESCAPE;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ break;
+ }
+
+ case 0:
+ {
+ return;
+ }
+
+ }
+
+ }
+ if( c == L'\'' )
+ {
+ mode = 0;
+ }
+
+ break;
+ }
+
+ /*
+ Mode 2 means double quoted string, i.e. "foo"
+ */
+ case 2:
+ {
+ switch( c )
+ {
+ case '"':
+ {
+ mode = 0;
+ break;
+ }
+
+ case '\\':
+ {
+ int start_pos = in_pos;
+ switch( buff[++in_pos] )
+ {
+ case L'\0':
+ {
+ return;
+ }
+
+ case '\\':
+ case L'$':
+ case '"':
+ {
+ color[start_pos] = HIGHLIGHT_ESCAPE;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ break;
+ }
+ }
+ break;
+ }
+
+ case '$':
+ {
+ color[in_pos] = HIGHLIGHT_OPERATOR;
+ color[in_pos+1] = HIGHLIGHT_NORMAL;
+ break;
+ }
+
+ }
+ break;
+ }
+ }
+ }
+}
+
void highlight_shell( wchar_t * buff,
int *color,
@@ -125,6 +398,12 @@ void highlight_shell( wchar_t * buff,
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
}
+
+ highlight_param( param,
+ &color[tok_get_pos( &tok )],
+ pos-tok_get_pos( &tok ),
+ error );
+
}
else
{
diff --git a/output.h b/output.h
index 443dfe71..1a42082e 100644
--- a/output.h
+++ b/output.h
@@ -22,6 +22,8 @@ enum
HIGHLIGHT_COMMENT,
HIGHLIGHT_MATCH,
HIGHLIGHT_SEARCH_MATCH,
+ HIGHLIGHT_OPERATOR,
+ HIGHLIGHT_ESCAPE,
}
;