diff --git a/builtin.c b/builtin.c index 4f4308b4e..7b849bcbb 100644 --- a/builtin.c +++ b/builtin.c @@ -876,6 +876,8 @@ static int builtin_functions( wchar_t **argv ) } else if( list ) { + int is_screen = !builtin_out_redirect && isatty(1); + al_init( &names ); function_get_names( &names, show_hidden ); names_arr = list_to_char_arr( &names ); @@ -883,13 +885,33 @@ static int builtin_functions( wchar_t **argv ) al_get_count( &names ), sizeof(wchar_t *), (int (*)(const void *, const void *))&wcsfilecmp ); - for( i=0; i debug_level ) return; @@ -826,10 +822,22 @@ void debug( int level, const wchar_t *msg, ... ) sb_printf( &sb, L"%ls: ", program_name ); sb_vprintf( &sb, msg, va ); va_end( va ); + + write_screen( (wchar_t *)sb.buff ); + + sb_destroy( &sb ); +} + +void write_screen( const wchar_t *msg ) +{ + const wchar_t *start, *pos; + int line_width = 0; + int tok_width = 0; + int screen_width = common_get_width(); if( screen_width ) { - start = pos = (wchar_t *)sb.buff; + start = pos = msg; while( 1 ) { int overflow = 0; @@ -901,11 +909,9 @@ void debug( int level, const wchar_t *msg, ... ) } else { - fwprintf( stderr, L"%ls", sb.buff ); - + fwprintf( stderr, L"%ls", msg ); } putwc( L'\n', stderr ); - sb_destroy( &sb ); } wchar_t *escape( const wchar_t *in, diff --git a/common.h b/common.h index 33eb8341b..f6dbb48a7 100644 --- a/common.h +++ b/common.h @@ -380,5 +380,12 @@ int common_get_height(); */ void common_handle_winch( int signal ); +/** + Write paragraph of output to screen. Ignore newlines in message and + perform internal line-breaking. +*/ +void write_screen( const wchar_t *msg ); + + #endif