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:
axel 2006-01-15 21:58:05 +10:00
parent 9942e2f19f
commit 9501dc83e6
3 changed files with 48 additions and 13 deletions

View file

@ -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,6 +885,24 @@ static int builtin_functions( wchar_t **argv )
al_get_count( &names ),
sizeof(wchar_t *),
(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++ )
{
sb_append2( sb_out,
@ -890,6 +910,8 @@ static int builtin_functions( wchar_t **argv )
L"\n",
(void *)0 );
}
}
free( names_arr );
al_destroy( &names );
return 0;

View file

@ -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;
@ -827,9 +823,21 @@ void debug( int level, const wchar_t *msg, ... )
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,

View file

@ -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