From 18c185c25623474a8b135d37304366e7731f27e4 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 27 May 2006 02:46:38 +1000 Subject: Add support for highlighting operators and escaped sequences darcs-hash:20060526164638-ac50b-2259579e0460df0641683ce6127bb8516fca8c7e.gz --- common.c | 15 --- common.h | 15 +++ doc_src/doc.hdr | 2 +- etc/fish_interactive.fish.in | 2 + highlight.c | 295 +++++++++++++++++++++++++++++++++++++++++-- output.h | 2 + 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 umask shellscript function. 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