From a02aa7a3166f2ba92cbb6eebc2b201ebb7a9f78b Mon Sep 17 00:00:00 2001 From: maxfl Date: Wed, 27 Jun 2012 07:17:00 +0400 Subject: [PATCH] Step coloring for fish_pager introduces new variable fish_pager_color_secondary to set background of every second completion line. It simplifies finding the options corresponding to given description. Default color is 151515. --- doc_src/index.hdr.in | 5 +++-- fish_pager.cpp | 22 +++++++++++-------- .../functions/__fish_config_interactive.fish | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 84eb58cd0..84ed5a551 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -1004,6 +1004,7 @@ highlighting in the completion pager: - \c fish_pager_color_completion, the color of the completion itself - \c fish_pager_color_description, the color of the completion description - \c fish_pager_color_progress, the color of the progress bar at the bottom left corner +- \c fish_pager_color_secondary, the background color of the every second completion Example: @@ -1227,8 +1228,8 @@ 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. Usually, the value of these variables will +fish_pager_color_description, \c fish_pager_color_progress +and \c fish_pager_color_secondary. Usually, the value of these variables will be one of \c black, \c red, \c green, \c brown, \c yellow, \c blue, \c magenta, \c purple, \c cyan, \c white or \c normal, but they can be an array containing any color options for the set_color command. diff --git a/fish_pager.cpp b/fish_pager.cpp index 1ca0f903b..afcda6740 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -77,7 +77,8 @@ enum HIGHLIGHT_PAGER_PREFIX, HIGHLIGHT_PAGER_COMPLETION, HIGHLIGHT_PAGER_DESCRIPTION, - HIGHLIGHT_PAGER_PROGRESS + HIGHLIGHT_PAGER_PROGRESS, + HIGHLIGHT_PAGER_SECONDARY } ; @@ -152,7 +153,8 @@ static const wchar_t *hightlight_var[] = L"fish_pager_color_prefix", L"fish_pager_color_completion", L"fish_pager_color_description", - L"fish_pager_color_progress" + L"fish_pager_color_progress", + L"fish_pager_color_secondary" } ; @@ -206,7 +208,7 @@ static rgb_color_t get_color( int highlight ) if( highlight < 0 ) return rgb_color_t::normal(); - if( highlight >= (4) ) + if( highlight >= (5) ) return rgb_color_t::normal(); val = wgetenv( hightlight_var[highlight]); @@ -389,7 +391,7 @@ static int print_max( const wchar_t *str, int max, int has_more ) /** Print the specified item using at the specified amount of space */ -static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) +static void completion_print_item( const wchar_t *prefix, comp_t *c, int width, bool primary ) { int comp_width=0, desc_width=0; int written=0; @@ -422,14 +424,15 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) } + rgb_color_t bg = primary ? rgb_color_t::normal() : get_color(HIGHLIGHT_PAGER_SECONDARY); for( size_t i=0; icomp.size(); i++ ) { const wcstring &comp = c->comp.at(i); if( i != 0 ) written += print_max( L" ", comp_width - written, 2 ); - set_color( get_color(HIGHLIGHT_PAGER_PREFIX),rgb_color_t::normal() ); + set_color( get_color(HIGHLIGHT_PAGER_PREFIX), bg ); written += print_max( prefix, comp_width - written, comp.empty()?0:1 ); - set_color( get_color(HIGHLIGHT_PAGER_COMPLETION),rgb_color_t::ignore() ); + set_color( get_color(HIGHLIGHT_PAGER_COMPLETION), bg); written += print_max( comp.c_str(), comp_width - written, i!=(c->comp.size()-1) ); } @@ -442,7 +445,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) writech( L' '); } written += print_max( L"(", 1, 0 ); - set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), rgb_color_t::ignore() ); + set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), bg); written += print_max( c->desc.c_str(), desc_width, 0 ); written += print_max( L")", 1, 0 ); } @@ -454,7 +457,8 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) writech( L' '); } } - + if ( !primary ) + set_color( rgb_color_t::normal(), rgb_color_t::normal() ); } /** @@ -495,7 +499,7 @@ static void completion_print( int cols, el = lst.at(j*rows + i ); - completion_print_item( prefix, el, width[j] - (is_last?0:2) ); + completion_print_item( prefix, el, width[j] - (is_last?0:2), i%2 ); if( !is_last) writestr( L" " ); diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 7b0cca367..03ce26614 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -122,6 +122,7 @@ function __fish_config_interactive -d "Initializations that should be performed set_default fish_pager_color_completion normal set_default fish_pager_color_description normal set_default fish_pager_color_progress cyan + set_default fish_pater_color_secondary 151515 # # Directory history colors