From 5938a930188b44b0c57969ff65aa13e7034aac21 Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Mon, 24 Sep 2007 18:49:33 +1000 Subject: [PATCH] Make prompt have its own line if we things don't fit on a single line darcs-hash:20070924084933-75c98-0b139cdab5da3f9c9f358d09275ed15fc0fbba52.gz --- screen.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/screen.c b/screen.c index f667188a9..5b4c1fcd9 100644 --- a/screen.c +++ b/screen.c @@ -53,6 +53,11 @@ efficient way for transforming that to the desired screen content. #include "screen.h" #include "env.h" +/** + The number of characters to indent new blocks + */ +#define INDENT_STEP 4 + /** Ugly kludge. The internal buffer used to store output of tputs. Since tputs external function can only take an integer and @@ -407,7 +412,7 @@ static void s_desired_append_char( screen_t *s, al_push( &s->desired, current ); s->desired_cursor[1]++; s->desired_cursor[0]=0; - for( i=0; i < prompt_width+indent*4; i++ ) + for( i=0; i < prompt_width+indent*INDENT_STEP; i++ ) { s_desired_append_char( s, L' ', 0, indent, prompt_width ); } @@ -805,7 +810,7 @@ void s_write( screen_t *s, /* Ignore huge prompts on small screens - only print a two character placeholder... */ - if( prompt_width > (screen_width/2) ) + if( prompt_width >= screen_width ) { prompt = L"> "; prompt_width = 2; @@ -819,13 +824,45 @@ void s_write( screen_t *s, return; } + int max_line_width = 0; + int current_line_width = 0; + + for( i=0; b[i]; i++ ) + { + if( b[i] == L'\n' ) + { + if( current_line_width > max_line_width ) + max_line_width = current_line_width; + current_line_width = indent[i]*INDENT_STEP; + } + else + { + current_line_width += wcwidth(b[i]); + } + } + if( current_line_width > max_line_width ) + max_line_width = current_line_width; + s_reset_arr( &s->desired ); s->desired_cursor[0] = s->desired_cursor[1] = 0; - - for( i=0; i= screen_width ) { - s_desired_append_char( s, L' ', 0, 0, prompt_width ); + s_desired_append_char( s, L'\n', 0, 0, 0 ); + prompt_width=0; } + else + { + for( i=0; i