From 9501dc83e645188cc3c90d086b08025fcd56afd1 Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 15 Jan 2006 21:58:05 +1000 Subject: [PATCH] Make the functions builtin display function listing on -n to a terminal in a human-friendly format darcs-hash:20060115115805-ac50b-fc5b468c0e68904e5cf934f43066ecfdf23e2a3b.gz --- builtin.c | 32 +++++++++++++++++++++++++++----- common.c | 22 ++++++++++++++-------- common.h | 7 +++++++ 3 files changed, 48 insertions(+), 13 deletions(-) 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