From 5165a22304903f22f44d58bc34269f6a4c6e48a6 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Wed, 11 Apr 2007 18:10:05 +0000 Subject: [PATCH] * Honor --color with --list. * Add --list-verbose option. * Make sure that help related options always come first in the help output. --- src/libvlc-common.c | 77 ++++++++++++++++++++++++++++++++++++++++----- src/libvlc-module.c | 5 +++ 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/libvlc-common.c b/src/libvlc-common.c index 687d187fac..79a0c5a5c8 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -108,7 +108,7 @@ static inline int LoadMessages (void); static int GetFilenames ( libvlc_int_t *, int, char *[] ); static void Help ( libvlc_int_t *, char const *psz_help_name ); static void Usage ( libvlc_int_t *, char const *psz_module_name ); -static void ListModules ( libvlc_int_t * ); +static void ListModules ( libvlc_int_t *, vlc_bool_t ); static void Version ( void ); #ifdef WIN32 @@ -499,7 +499,13 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) /* Check for module list option */ else if( config_GetInt( p_libvlc, "list" ) ) { - ListModules( p_libvlc ); + ListModules( p_libvlc, VLC_FALSE ); + b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; + } + else if( config_GetInt( p_libvlc, "list-verbose" ) ) + { + ListModules( p_libvlc, VLC_TRUE ); b_exit = VLC_TRUE; i_ret = VLC_EEXITSUCCESS; } @@ -697,7 +703,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) } } /* we unreference the connection when we've finished with it */ - if( p_conn ) dbus_connection_unref( p_conn ); + if( p_conn ) dbus_connection_unref( p_conn ); } #endif @@ -1335,6 +1341,11 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name ) /* List all modules */ p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); + /* Ugly hack to make sure that the help options always come first + * (part 1) */ + if( !psz_module_name ) + Usage( p_this, "help" ); + /* Enumerate the config for each module */ for( i_index = 0; i_index < p_list->i_count; i_index++ ) { @@ -1363,6 +1374,12 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name ) continue; } + b_help_module = !strcmp( "help", p_parser->psz_object_name ); + /* Ugly hack to make sure that the help options always come first + * (part 2) */ + if( !psz_module_name && b_help_module ) + continue; + /* Ignore modules with only advanced config options if requested */ if( !b_advanced ) { @@ -1392,8 +1409,6 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name ) utf8_fprintf( stdout, " %s\n", p_parser->psz_help ); } - b_help_module = !strcmp( "help", p_parser->psz_object_name ); - /* Print module options */ for( p_item = p_parser->p_config; p_item < p_end; @@ -1692,13 +1707,15 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name ) * Print a list of all available modules (builtins and plugins) and a short * description for each one. *****************************************************************************/ -static void ListModules( libvlc_int_t *p_this ) +static void ListModules( libvlc_int_t *p_this, vlc_bool_t b_verbose ) { vlc_list_t *p_list = NULL; module_t *p_parser = NULL; char psz_spaces[22]; int i_index; + vlc_bool_t b_color = config_GetInt( p_this, "color" ); + memset( psz_spaces, ' ', 22 ); #ifdef WIN32 @@ -1721,8 +1738,52 @@ static void ListModules( libvlc_int_t *p_this ) if( i < 0 ) i = 0; psz_spaces[i] = 0; - utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name, - psz_spaces, p_parser->psz_longname ); + if( b_color ) + utf8_fprintf( stdout, GREEN" %s%s "WHITE"%s\n"GRAY, + p_parser->psz_object_name, + psz_spaces, + p_parser->psz_longname ); + else + utf8_fprintf( stdout, " %s%s %s\n", + p_parser->psz_object_name, + psz_spaces, p_parser->psz_longname ); + + if( b_verbose ) + { + const char **pp_shortcut = p_parser->pp_shortcuts; + while( pp_shortcut && *pp_shortcut ) + { + if( strcmp( *pp_shortcut, p_parser->psz_object_name ) ) + { + if( b_color ) + utf8_fprintf( stdout, CYAN" s %s\n"GRAY, + *pp_shortcut ); + else + utf8_fprintf( stdout, " s %s\n", + *pp_shortcut ); + } + pp_shortcut++; + } + if( p_parser->psz_capability ) + { + if( b_color ) + utf8_fprintf( stdout, MAGENTA" c %s (%d)\n"GRAY, + p_parser->psz_capability, + p_parser->i_score ); + else + utf8_fprintf( stdout, " c %s (%d)\n", + p_parser->psz_capability, + p_parser->i_score ); + } + if( p_parser->psz_program ) + { + if( b_color ) + utf8_fprintf( stdout, YELLOW " p %s\n"GRAY, + p_parser->psz_program ); + else + utf8_fprintf( stdout, " p %s\n", p_parser->psz_program ); + } + } psz_spaces[i] = ' '; } diff --git a/src/libvlc-module.c b/src/libvlc-module.c index 8dbd74dc13..5d724dddc0 100644 --- a/src/libvlc-module.c +++ b/src/libvlc-module.c @@ -2204,6 +2204,11 @@ const module_config_t libvlc_config[] = .i_short = 'l', .psz_text = N_("print a list of available modules") }, + { + .i_type = CONFIG_ITEM_BOOL, + .psz_name = "list-verbose", + .psz_text = N_("print a list of available modules with extra detail") + }, { .i_type = CONFIG_ITEM_STRING, .psz_name = "module", -- 2.39.2