aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--common.h11
-rw-r--r--etc/fish_interactive.fish.in6
-rw-r--r--output.c84
-rw-r--r--output.h7
-rw-r--r--reader.c4
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
@@ -21,17 +21,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.
*/
#define ENCODE_DIRECT_BASE 0xf100
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<COLORS; i++ )
+ al_init( &el );
+ expand_variable_array( val, &el );
+
+ for( j=0; j<al_get_count( &el ); j++ )
{
- if( wcscasecmp( col[i], val ) == 0 )
+ wchar_t *next = (wchar_t *)al_get( &el, j );
+
+ is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
+ is_bold |= wcscmp( next, L"-b" ) == 0;
+
+ for( i=0; i<COLORS; i++ )
{
- color = col_idx[i];
- break;
+ if( wcscasecmp( col[i], next ) == 0 )
+ {
+ color = col_idx[i];
+ break;
+ }
}
+
}
-
- if( color >= 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
{