mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Make the functions builtin display function listing on -n to a terminal in a human-friendly format
darcs-hash:20060115115805-ac50b-fc5b468c0e68904e5cf934f43066ecfdf23e2a3b.gz
This commit is contained in:
parent
9942e2f19f
commit
9501dc83e6
3 changed files with 48 additions and 13 deletions
22
builtin.c
22
builtin.c
|
@ -876,6 +876,8 @@ static int builtin_functions( wchar_t **argv )
|
||||||
}
|
}
|
||||||
else if( list )
|
else if( list )
|
||||||
{
|
{
|
||||||
|
int is_screen = !builtin_out_redirect && isatty(1);
|
||||||
|
|
||||||
al_init( &names );
|
al_init( &names );
|
||||||
function_get_names( &names, show_hidden );
|
function_get_names( &names, show_hidden );
|
||||||
names_arr = list_to_char_arr( &names );
|
names_arr = list_to_char_arr( &names );
|
||||||
|
@ -883,6 +885,24 @@ static int builtin_functions( wchar_t **argv )
|
||||||
al_get_count( &names ),
|
al_get_count( &names ),
|
||||||
sizeof(wchar_t *),
|
sizeof(wchar_t *),
|
||||||
(int (*)(const void *, const void *))&wcsfilecmp );
|
(int (*)(const void *, const void *))&wcsfilecmp );
|
||||||
|
if( is_screen )
|
||||||
|
{
|
||||||
|
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++ )
|
for( i=0; i<al_get_count( &names ); i++ )
|
||||||
{
|
{
|
||||||
sb_append2( sb_out,
|
sb_append2( sb_out,
|
||||||
|
@ -890,6 +910,8 @@ static int builtin_functions( wchar_t **argv )
|
||||||
L"\n",
|
L"\n",
|
||||||
(void *)0 );
|
(void *)0 );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free( names_arr );
|
free( names_arr );
|
||||||
al_destroy( &names );
|
al_destroy( &names );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
22
common.c
22
common.c
|
@ -812,10 +812,6 @@ void debug( int level, const wchar_t *msg, ... )
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
string_buffer_t sb;
|
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 )
|
if( level > debug_level )
|
||||||
return;
|
return;
|
||||||
|
@ -827,9 +823,21 @@ void debug( int level, const wchar_t *msg, ... )
|
||||||
sb_vprintf( &sb, msg, va );
|
sb_vprintf( &sb, msg, va );
|
||||||
va_end( 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 )
|
if( screen_width )
|
||||||
{
|
{
|
||||||
start = pos = (wchar_t *)sb.buff;
|
start = pos = msg;
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
int overflow = 0;
|
int overflow = 0;
|
||||||
|
@ -901,11 +909,9 @@ void debug( int level, const wchar_t *msg, ... )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fwprintf( stderr, L"%ls", sb.buff );
|
fwprintf( stderr, L"%ls", msg );
|
||||||
|
|
||||||
}
|
}
|
||||||
putwc( L'\n', stderr );
|
putwc( L'\n', stderr );
|
||||||
sb_destroy( &sb );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *escape( const wchar_t *in,
|
wchar_t *escape( const wchar_t *in,
|
||||||
|
|
7
common.h
7
common.h
|
@ -380,5 +380,12 @@ int common_get_height();
|
||||||
*/
|
*/
|
||||||
void common_handle_winch( int signal );
|
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
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue