aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-15 21:58:05 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-15 21:58:05 +1000
commit9501dc83e645188cc3c90d086b08025fcd56afd1 (patch)
treea6155e0aae43af73f9148d1c5f374a74a1a2b2fc /builtin.c
parent9942e2f19fbbefdd7857a1fe08b4a50f99bba7e5 (diff)
Make the functions builtin display function listing on -n to a terminal in a human-friendly format
darcs-hash:20060115115805-ac50b-fc5b468c0e68904e5cf934f43066ecfdf23e2a3b.gz
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/builtin.c b/builtin.c
index 4f4308b4..7b849bcb 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<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;