mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Add better debbuging information when writembs is called with null value.
darcs-hash:20070909140436-75c98-b6c925c441ebaa349f998b95314295296fb36252.gz
This commit is contained in:
parent
370aeec44d
commit
76bb8e79b2
4 changed files with 124 additions and 74 deletions
153
fish_pager.c
153
fish_pager.c
|
@ -253,8 +253,8 @@ static int try_sequence( char *seq )
|
||||||
wint_t c=0;
|
wint_t c=0;
|
||||||
|
|
||||||
for( j=0;
|
for( j=0;
|
||||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||||
j++ )
|
j++ )
|
||||||
;
|
;
|
||||||
|
|
||||||
if( seq[j] == '\0' )
|
if( seq[j] == '\0' )
|
||||||
|
@ -408,8 +408,8 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
int desc_all = c->desc_width?c->desc_width+4:0;
|
int desc_all = c->desc_width?c->desc_width+4:0;
|
||||||
|
|
||||||
comp_width = maxi( mini( c->comp_width,
|
comp_width = maxi( mini( c->comp_width,
|
||||||
2*(width-4)/3 ),
|
2*(width-4)/3 ),
|
||||||
width - desc_all );
|
width - desc_all );
|
||||||
if( c->desc_width )
|
if( c->desc_width )
|
||||||
desc_width = width-comp_width-4;
|
desc_width = width-comp_width-4;
|
||||||
else
|
else
|
||||||
|
@ -438,7 +438,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
}
|
}
|
||||||
written += print_max( L"(", 1, 0 );
|
written += print_max( L"(", 1, 0 );
|
||||||
set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ),
|
set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ),
|
||||||
FISH_COLOR_IGNORE );
|
FISH_COLOR_IGNORE );
|
||||||
written += print_max( c->desc, desc_width, 0 );
|
written += print_max( c->desc, desc_width, 0 );
|
||||||
written += print_max( L")", 1, 0 );
|
written += print_max( L")", 1, 0 );
|
||||||
}
|
}
|
||||||
|
@ -467,12 +467,12 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void completion_print( int cols,
|
static void completion_print( int cols,
|
||||||
int *width,
|
int *width,
|
||||||
int row_start,
|
int row_start,
|
||||||
int row_stop,
|
int row_stop,
|
||||||
wchar_t *prefix,
|
wchar_t *prefix,
|
||||||
int is_quoted,
|
int is_quoted,
|
||||||
array_list_t *l)
|
array_list_t *l)
|
||||||
{
|
{
|
||||||
|
|
||||||
int rows = (al_get_count( l )-1)/cols+1;
|
int rows = (al_get_count( l )-1)/cols+1;
|
||||||
|
@ -520,9 +520,9 @@ static void completion_print( int cols,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int completion_try_print( int cols,
|
static int completion_try_print( int cols,
|
||||||
wchar_t *prefix,
|
wchar_t *prefix,
|
||||||
int is_quoted,
|
int is_quoted,
|
||||||
array_list_t *l )
|
array_list_t *l )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The calculated preferred width of each column
|
The calculated preferred width of each column
|
||||||
|
@ -578,9 +578,9 @@ static int completion_try_print( int cols,
|
||||||
min += 2;
|
min += 2;
|
||||||
}
|
}
|
||||||
min_width[j] = maxi( min_width[j],
|
min_width[j] = maxi( min_width[j],
|
||||||
min );
|
min );
|
||||||
pref_width[j] = maxi( pref_width[j],
|
pref_width[j] = maxi( pref_width[j],
|
||||||
pref );
|
pref );
|
||||||
}
|
}
|
||||||
min_tot_width += min_width[j];
|
min_tot_width += min_width[j];
|
||||||
pref_tot_width += pref_width[j];
|
pref_tot_width += pref_width[j];
|
||||||
|
@ -614,8 +614,8 @@ static int completion_try_print( int cols,
|
||||||
pref_tot_width-termsize.ws_col );
|
pref_tot_width-termsize.ws_col );
|
||||||
*/
|
*/
|
||||||
if( min_tot_width < termsize.ws_col &&
|
if( min_tot_width < termsize.ws_col &&
|
||||||
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
||||||
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Terminal almost wide enough, or squeezing makes the
|
Terminal almost wide enough, or squeezing makes the
|
||||||
|
@ -676,12 +676,12 @@ static int completion_try_print( int cols,
|
||||||
writembs(enter_ca_mode);
|
writembs(enter_ca_mode);
|
||||||
|
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
0,
|
0,
|
||||||
termsize.ws_row-1,
|
termsize.ws_row-1,
|
||||||
prefix,
|
prefix,
|
||||||
is_quoted,
|
is_quoted,
|
||||||
l);
|
l);
|
||||||
/*
|
/*
|
||||||
List does not fit on screen. Print one screenfull and
|
List does not fit on screen. Print one screenfull and
|
||||||
leave a scrollable interface
|
leave a scrollable interface
|
||||||
|
@ -692,12 +692,12 @@ static int completion_try_print( int cols,
|
||||||
sb_init( &msg );
|
sb_init( &msg );
|
||||||
|
|
||||||
set_color( FISH_COLOR_BLACK,
|
set_color( FISH_COLOR_BLACK,
|
||||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||||
sb_printf( &msg,
|
sb_printf( &msg,
|
||||||
_(L" %d to %d of %d \r"),
|
_(L" %d to %d of %d \r"),
|
||||||
pos,
|
pos,
|
||||||
pos+termsize.ws_row-1,
|
pos+termsize.ws_row-1,
|
||||||
rows );
|
rows );
|
||||||
|
|
||||||
writestr((wchar_t *)msg.buff);
|
writestr((wchar_t *)msg.buff);
|
||||||
sb_destroy( &msg );
|
sb_destroy( &msg );
|
||||||
|
@ -715,14 +715,14 @@ static int completion_try_print( int cols,
|
||||||
writembs(tparm( cursor_address, 0, 0));
|
writembs(tparm( cursor_address, 0, 0));
|
||||||
writembs(scroll_reverse);
|
writembs(scroll_reverse);
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
pos,
|
pos,
|
||||||
pos+1,
|
pos+1,
|
||||||
prefix,
|
prefix,
|
||||||
is_quoted,
|
is_quoted,
|
||||||
l );
|
l );
|
||||||
writembs( tparm( cursor_address,
|
writembs( tparm( cursor_address,
|
||||||
termsize.ws_row-1, 0) );
|
termsize.ws_row-1, 0) );
|
||||||
writembs(clr_eol );
|
writembs(clr_eol );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -736,12 +736,12 @@ static int completion_try_print( int cols,
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
pos+termsize.ws_row-2,
|
pos+termsize.ws_row-2,
|
||||||
pos+termsize.ws_row-1,
|
pos+termsize.ws_row-1,
|
||||||
prefix,
|
prefix,
|
||||||
is_quoted,
|
is_quoted,
|
||||||
l );
|
l );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -750,17 +750,17 @@ static int completion_try_print( int cols,
|
||||||
{
|
{
|
||||||
|
|
||||||
npos = mini( rows - termsize.ws_row+1,
|
npos = mini( rows - termsize.ws_row+1,
|
||||||
pos + termsize.ws_row-1 );
|
pos + termsize.ws_row-1 );
|
||||||
if( npos != pos )
|
if( npos != pos )
|
||||||
{
|
{
|
||||||
pos = npos;
|
pos = npos;
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
pos,
|
pos,
|
||||||
pos+termsize.ws_row-1,
|
pos+termsize.ws_row-1,
|
||||||
prefix,
|
prefix,
|
||||||
is_quoted,
|
is_quoted,
|
||||||
l );
|
l );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -774,18 +774,18 @@ static int completion_try_print( int cols,
|
||||||
case PAGE_UP:
|
case PAGE_UP:
|
||||||
{
|
{
|
||||||
npos = maxi( 0,
|
npos = maxi( 0,
|
||||||
pos - termsize.ws_row+1 );
|
pos - termsize.ws_row+1 );
|
||||||
|
|
||||||
if( npos != pos )
|
if( npos != pos )
|
||||||
{
|
{
|
||||||
pos = npos;
|
pos = npos;
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
pos,
|
pos,
|
||||||
pos+termsize.ws_row-1,
|
pos+termsize.ws_row-1,
|
||||||
prefix,
|
prefix,
|
||||||
is_quoted,
|
is_quoted,
|
||||||
l );
|
l );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1008,8 +1008,8 @@ static void init( int mangle_descriptors, int out )
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
static struct termios pager_modes;
|
static struct termios pager_modes;
|
||||||
|
char *term;
|
||||||
|
|
||||||
if( mangle_descriptors )
|
if( mangle_descriptors )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1076,22 +1076,23 @@ static void init( int mangle_descriptors, int out )
|
||||||
|
|
||||||
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
||||||
memcpy( &saved_modes,
|
memcpy( &saved_modes,
|
||||||
&pager_modes,
|
&pager_modes,
|
||||||
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
||||||
|
|
||||||
pager_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
pager_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
||||||
pager_modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
pager_modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
||||||
pager_modes.c_cc[VMIN]=1;
|
pager_modes.c_cc[VMIN]=1;
|
||||||
pager_modes.c_cc[VTIME]=0;
|
pager_modes.c_cc[VTIME]=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||||
{
|
{
|
||||||
wperror(L"tcsetattr");
|
wperror(L"tcsetattr");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
||||||
{
|
{
|
||||||
|
@ -1099,6 +1100,14 @@ static void init( int mangle_descriptors, int out )
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
term = getenv("TERM");
|
||||||
|
if( term )
|
||||||
|
{
|
||||||
|
wchar_t *wterm = str2wcs(term);
|
||||||
|
output_set_term( wterm );
|
||||||
|
free( wterm );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1137,7 +1146,7 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
c = getc( file );
|
c = getc( file );
|
||||||
if( c == EOF )
|
if( c == EOF )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -1265,10 +1274,10 @@ int main( int argc, char **argv )
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
2
input.c
2
input.c
|
@ -1435,6 +1435,8 @@ int input_init()
|
||||||
debug( 0, _( L"Could not set up terminal" ) );
|
debug( 0, _( L"Could not set up terminal" ) );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
output_set_term( env_get( L"TERM" ) );
|
||||||
|
|
||||||
hash_init( &all_mappings, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( &all_mappings, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
17
output.c
17
output.c
|
@ -121,6 +121,9 @@ static char *writestr_buff = 0;
|
||||||
|
|
||||||
static int (*out)(char c) = &writeb_internal;
|
static int (*out)(char c) = &writeb_internal;
|
||||||
|
|
||||||
|
static wchar_t *current_term = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cleanup function. Run automatically through halloc
|
Cleanup function. Run automatically through halloc
|
||||||
*/
|
*/
|
||||||
|
@ -366,7 +369,7 @@ int writeb( tputs_arg_t b )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writembs( char *str )
|
int writembs_internal( char *str )
|
||||||
{
|
{
|
||||||
CHECK( str, 1 );
|
CHECK( str, 1 );
|
||||||
|
|
||||||
|
@ -580,3 +583,15 @@ int output_color_code( const wchar_t *val )
|
||||||
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void output_set_term( wchar_t *term )
|
||||||
|
{
|
||||||
|
current_term = halloc_wcsdup(global_context, term);
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *output_get_term()
|
||||||
|
{
|
||||||
|
return current_term ? current_term : L"<unknown>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
26
output.h
26
output.h
|
@ -73,13 +73,34 @@ enum
|
||||||
|
|
||||||
void set_color( int c, int c2 );
|
void set_color( int c, int c2 );
|
||||||
|
|
||||||
|
|
||||||
|
#define writembs( mbs ) \
|
||||||
|
{ \
|
||||||
|
char *tmp = mbs; \
|
||||||
|
if( tmp ) \
|
||||||
|
{ \
|
||||||
|
writembs_internal( tmp ); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
debug( 0, \
|
||||||
|
_(L"Tried to use terminfo string %s on line %d of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"), \
|
||||||
|
#mbs, \
|
||||||
|
__LINE__, \
|
||||||
|
__FILE__, \
|
||||||
|
output_get_term(), \
|
||||||
|
PACKAGE_BUGREPORT); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Write a char * narrow string to FD 1, needed for the terminfo
|
Write a char * narrow string to FD 1, needed for the terminfo
|
||||||
strings. This is usually just a wrapper aound tputs, using writeb
|
strings. This is usually just a wrapper aound tputs, using writeb
|
||||||
as the sending function. But a weird bug on PPC Linux means that on
|
as the sending function. But a weird bug on PPC Linux means that on
|
||||||
this platform, write is instead used directly.
|
this platform, write is instead used directly.
|
||||||
*/
|
*/
|
||||||
int writembs( char *str );
|
int writembs_internal( char *str );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Write a wide character using the output method specified using output_set_writer().
|
Write a wide character using the output method specified using output_set_writer().
|
||||||
|
@ -126,4 +147,7 @@ void output_set_writer( int (*writer)(char) );
|
||||||
|
|
||||||
int (*output_get_writer())(char) ;
|
int (*output_get_writer())(char) ;
|
||||||
|
|
||||||
|
void output_set_term( wchar_t *term );
|
||||||
|
wchar_t *output_get_term();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue