From 8258961c2983ee370f26f775ec12e0ecf921ac38 Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 14 Feb 2006 21:33:47 +1000 Subject: [PATCH] Fix minor display bugs and a memory leak in fish_pager darcs-hash:20060214113347-ac50b-302a7da47f9c07af3acc9a2dcc5c8007127fc3a2.gz --- fish_pager.c | 75 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/fish_pager.c b/fish_pager.c index 42a8b304e..abe6c5223 100644 --- a/fish_pager.c +++ b/fish_pager.c @@ -243,6 +243,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) int i; int written=0; +// debug( 1, L"print %ls", al_get(c->comp, 0 ) ); if( c->pref_width <= width ) { /* @@ -264,31 +265,46 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width ) comp_width = maxi( mini( c->comp_width, 2*(width-4)/3 ), width - desc_all ); + if( c->desc_width ) + desc_width = width-comp_width-4; + else + c->desc_width=0; - desc_width = width-comp_width-4; } for( i=0; icomp ); i++ ) { if( i != 0 ) - written += print_max( L" ", comp_width - written, 1 ); + written += print_max( L" ", comp_width - written, 2 ); set_color( get_color(HIGHLIGHT_PAGER_PREFIX),FISH_COLOR_NORMAL ); written += print_max( prefix, comp_width - written, 1 ); set_color( get_color(HIGHLIGHT_PAGER_COMPLETION),FISH_COLOR_IGNORE ); written += print_max( (wchar_t *)al_get( c->comp, i ), comp_width - written, i!=(al_get_count(c->comp)-1) ); } - while( written < (width-desc_width-2)) + + if( desc_width ) { - written++; - writech( L' '); + while( written < (width-desc_width-2)) + { + written++; + writech( L' '); + } + written += print_max( L"(", 1, 0 ); + set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), + FISH_COLOR_IGNORE ); + written += print_max( c->desc, desc_width, 0 ); + written += print_max( L")", 1, 0 ); + } + else + { + while( written < width ) + { + written++; + writech( L' '); + } } - written += print_max( L"(", 1, 0 ); - set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), - FISH_COLOR_IGNORE ); - written += print_max( c->desc, desc_width, 0 ); - written += print_max( L")", 1, 0 ); } /** @@ -322,14 +338,16 @@ static void completion_print( int cols, { comp_t *el; + int is_last = (j==(cols-1)); + if( al_get_count( l ) <= j*rows + i ) continue; el = (comp_t *)al_get( l, j*rows + i ); - completion_print_item( prefix, el, width[j] ); + completion_print_item( prefix, el, width[j] - (is_last?0:2) ); - if( j != cols-1) + if( !is_last) writestr( L" " ); } writech( L'\n' ); @@ -683,7 +701,7 @@ static void join_completions( array_list_t *l ) { int i, in, out; hash_table_t desc_table; - + hash_init( &desc_table, &hash_wcs_func, &hash_wcs_cmp ); for( i=0; icomp = al_halloc( global_context ); - for( start=end=next; *end; end++ ) + for( start=end=next; 1; end++ ) { wchar_t c = *end; - if( c == COMPLETE_ITEM_SEP || c==COMPLETE_SEP ) + if( (c == COMPLETE_ITEM_SEP) || (c==COMPLETE_SEP) || !c) { *end = 0; wchar_t * str = escape( start, 1 ); @@ -770,10 +792,14 @@ static void mangle_completions( array_list_t *l, const wchar_t *prefix ) { comp->desc = halloc_wcsdup( global_context, start ); break; - } + } + + if( !c ) + break; + } - comp->comp_width += my_wcswidth(prefix)*al_get_count(comp->comp) + (al_get_count(comp->comp)-1); + comp->comp_width += my_wcswidth(prefix)*al_get_count(comp->comp) + 2*(al_get_count(comp->comp)-1); comp->desc_width = comp->desc?my_wcswidth( comp->desc ):0; comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0); @@ -915,12 +941,11 @@ int main( int argc, char **argv ) al_push( comp, wcs ); } } - + mangle_descriptions( comp ); if( wcscmp( prefix, L"-" ) == 0 ) join_completions( comp ); mangle_completions( comp, prefix ); - for( i = 6; i>0; i-- ) {