diff options
-rw-r--r-- | builtin.c | 32 | ||||
-rw-r--r-- | common.c | 22 | ||||
-rw-r--r-- | common.h | 7 |
3 files changed, 48 insertions, 13 deletions
@@ -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<al_get_count( &names ); i++ ) + if( is_screen ) { - sb_append2( sb_out, - names_arr[i], - L"\n", - (void *)0 ); + string_buffer_t buff; + sb_init( &buff ); + + for( i=0; i<al_get_count( &names ); i++ ) + { + sb_append2( &buff, + names_arr[i], + L", ", + (void *)0 ); + } + + write_screen( (wchar_t *)buff.buff ); + sb_destroy( &buff ); } + else + { + for( i=0; i<al_get_count( &names ); i++ ) + { + sb_append2( sb_out, + names_arr[i], + L"\n", + (void *)0 ); + } + } + free( names_arr ); al_destroy( &names ); return 0; @@ -812,10 +812,6 @@ void debug( int level, const wchar_t *msg, ... ) { va_list va; string_buffer_t sb; - wchar_t *start, *pos; - int line_width = 0; - int tok_width = 0; - int screen_width = common_get_width(); if( level > 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, @@ -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 |