Make prompt have its own line if we things don't fit on a single line

darcs-hash:20070924084933-75c98-0b139cdab5da3f9c9f358d09275ed15fc0fbba52.gz
This commit is contained in:
liljencrantz 2007-09-24 18:49:33 +10:00
parent 79ac330afb
commit 5938a93018

View File

@ -53,6 +53,11 @@ efficient way for transforming that to the desired screen content.
#include "screen.h" #include "screen.h"
#include "env.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 Ugly kludge. The internal buffer used to store output of
tputs. Since tputs external function can only take an integer and 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 ); al_push( &s->desired, current );
s->desired_cursor[1]++; s->desired_cursor[1]++;
s->desired_cursor[0]=0; 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 ); 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... 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 = L"> ";
prompt_width = 2; prompt_width = 2;
@ -819,13 +824,45 @@ void s_write( screen_t *s,
return; 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_reset_arr( &s->desired );
s->desired_cursor[0] = s->desired_cursor[1] = 0; s->desired_cursor[0] = s->desired_cursor[1] = 0;
/*
Check if we are overflowing. If so, give the prompt its own line to improve the situation.
*/
if( max_line_width + prompt_width >= screen_width )
{
s_desired_append_char( s, L'\n', 0, 0, 0 );
prompt_width=0;
}
else
{
for( i=0; i<prompt_width; i++ ) for( i=0; i<prompt_width; i++ )
{ {
s_desired_append_char( s, L' ', 0, 0, prompt_width ); s_desired_append_char( s, L' ', 0, 0, prompt_width );
} }
}
for( i=0; b[i]; i++ ) for( i=0; b[i]; i++ )
{ {