From bffff77d17d8e6744a9c1cf2d6a88af1da5e985e Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 27 May 2006 23:39:30 +1000 Subject: Add support for bold highligting darcs-hash:20060527133930-ac50b-515d0887567c0e89fdfe10fe8310d6ebb4485974.gz --- common.h | 11 ------ etc/fish_interactive.fish.in | 6 ++-- output.c | 84 +++++++++++++++++++++++++++++++++++--------- output.h | 7 ++-- reader.c | 4 +-- 5 files changed, 78 insertions(+), 34 deletions(-) diff --git a/common.h b/common.h index e2a4379f..4dbb83a0 100644 --- a/common.h +++ b/common.h @@ -20,17 +20,6 @@ */ #define MAX_UTF8_BYTES 6 -/** - Color code for set_color. Does not update the color. -*/ - -#define FISH_COLOR_IGNORE -1 - -/** - Color code for set_color. Sets the default color. -*/ -#define FISH_COLOR_RESET -2 - /** This is in the unicode private use area. */ diff --git a/etc/fish_interactive.fish.in b/etc/fish_interactive.fish.in index 33eb050b..da41d92f 100644 --- a/etc/fish_interactive.fish.in +++ b/etc/fish_interactive.fish.in @@ -68,11 +68,11 @@ end set_default fish_color_normal normal 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_comment red +set_default fish_color_error red --bold set_default fish_color_escape cyan set_default fish_color_operator cyan -set_default fish_color_quote blue +set_default fish_color_quote brown set_default fish_color_cwd green diff --git a/output.c b/output.c index dda4aa2e..044d4f8f 100644 --- a/output.c +++ b/output.c @@ -128,9 +128,20 @@ void set_color( int c, int c2 ) { static int last_color = FISH_COLOR_NORMAL; static int last_color2 = FISH_COLOR_NORMAL; + static int was_bold=0; int bg_set=0, last_bg_set=0; char *fg = 0, *bg=0; + int is_bold = 0; + + is_bold |= (c&FISH_COLOR_BOLD)!=0; + is_bold |= (c2&FISH_COLOR_BOLD)!=0; + +// debug( 1, L"WOO %d %d %d", is_bold, c&FISH_COLOR_BOLD,c2&FISH_COLOR_BOLD); + + c = c&(~FISH_COLOR_BOLD); + c2 = c2&(~FISH_COLOR_BOLD); + if( (set_a_foreground != 0) && (strlen( set_a_foreground) != 0 ) ) { fg = set_a_foreground; @@ -145,14 +156,31 @@ void set_color( int c, int c2 ) if( (c == FISH_COLOR_RESET) || (c2 == FISH_COLOR_RESET)) { c = c2 = FISH_COLOR_NORMAL; + was_bold=0; if( fg ) { + /* + If we exit attibute mode, we must first set a color, or + previously coloured text might lose it's + color. Terminals are weird... + */ writembs( tparm( fg, 0 ) ); } writembs( exit_attribute_mode ); return; } + if( was_bold && !is_bold ) + { + /* + Only way to exit bold mode is a reset of all attributes. + */ + writembs( exit_attribute_mode ); + last_color = FISH_COLOR_NORMAL; + last_color2 = FISH_COLOR_NORMAL; + was_bold=0; + } + if( last_color2 != FISH_COLOR_NORMAL && last_color2 != FISH_COLOR_RESET && last_color2 != FISH_COLOR_IGNORE ) @@ -164,7 +192,6 @@ void set_color( int c, int c2 ) } if( c2 != FISH_COLOR_NORMAL && - c2 != FISH_COLOR_RESET && c2 != FISH_COLOR_IGNORE ) { /* @@ -180,7 +207,8 @@ void set_color( int c, int c2 ) { /* Background color changed and is set, so we enter bold - mode to make reading easier + mode to make reading easier. This means bold mode is + _always_ on when the background color is set. */ writembs( enter_bold_mode ); } @@ -252,8 +280,21 @@ void set_color( int c, int c2 ) last_color2 = c2; } } + + /* + Lastly, we set bold mode correctly + */ + if( (enter_bold_mode != 0) && (strlen(enter_bold_mode) > 0) && !bg_set ) + { + if( is_bold && !was_bold ) + { + writembs( tparm( enter_bold_mode ) ); + } + was_bold = is_bold; + } } + /** perm_left_cursor and parm_right_cursor don't seem to be properly emulated by many terminal emulators, so we only use plain @@ -475,23 +516,34 @@ int writespace( int c ) int output_color_code( const wchar_t *val ) { - int i, color=-1; + int j, i, color=FISH_COLOR_NORMAL; + array_list_t el; + int is_bold=0; + + if( !val ) + return FISH_COLOR_NORMAL; - for( i=0; i=3; + is_bold |= wcscmp( next, L"-b" ) == 0; + + for( i=0; i= 0 ) - { - return color; - } - else - { - return FISH_COLOR_NORMAL; - } + + return color | (is_bold?FISH_COLOR_BOLD:0); + } diff --git a/output.h b/output.h index 094f1b37..434cbc61 100644 --- a/output.h +++ b/output.h @@ -41,10 +41,13 @@ enum FISH_COLOR_CYAN, FISH_COLOR_WHITE, /** The default fg color of the terminal */ - FISH_COLOR_NORMAL + FISH_COLOR_NORMAL, + FISH_COLOR_IGNORE, + FISH_COLOR_RESET } ; - + +#define FISH_COLOR_BOLD 0x80 /** Sets the fg and bg color. May be called as often as you like, since diff --git a/reader.c b/reader.c index 3dc67b73..2b40702d 100644 --- a/reader.c +++ b/reader.c @@ -917,7 +917,7 @@ void repaint() if( steps ) move_cursor( -steps ); - set_color( FISH_COLOR_NORMAL, -1 ); + set_color( FISH_COLOR_NORMAL, FISH_COLOR_IGNORE ); reader_save_status(); } @@ -1144,7 +1144,7 @@ static int insert_char( int c ) } else writech(c); - set_color( FISH_COLOR_NORMAL, -1 ); + set_color( FISH_COLOR_NORMAL, FISH_COLOR_IGNORE ); } else { -- cgit v1.2.3