mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Add -dump-config option.
This commit is contained in:
parent
9af191de26
commit
77a4d97262
5 changed files with 96 additions and 0 deletions
|
@ -239,6 +239,13 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam
|
|||
*/
|
||||
void rofi_theme_print ( ThemeWidget *widget );
|
||||
|
||||
/**
|
||||
* @param widget The widget handle.
|
||||
*
|
||||
* Print out the theme and config to the commandline.
|
||||
*/
|
||||
void rofi_dump_config ( ThemeWidget *widget );
|
||||
|
||||
/**
|
||||
* @param type The type of the property to create.
|
||||
*
|
||||
|
|
|
@ -165,5 +165,10 @@ char ** config_parser_return_display_help ( unsigned int *length );
|
|||
* @returns true when failed to set property.
|
||||
*/
|
||||
gboolean config_parse_set_property ( const Property *p, char **error );
|
||||
|
||||
/**
|
||||
* @brief Dump configuration in rasi format.
|
||||
*/
|
||||
void config_parse_dump_config ( void );
|
||||
/* @}*/
|
||||
#endif
|
||||
|
|
|
@ -267,6 +267,8 @@ static void print_main_application_options ( int is_term )
|
|||
print_help_msg ( "-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
|
||||
print_help_msg ( "-no-lazy-grab", "", "Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
|
||||
print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term );
|
||||
print_help_msg ( "-dump-config", "", "Dump the current configuration and theme in rasi format and exit.", NULL, is_term );
|
||||
print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term );
|
||||
}
|
||||
static void help ( G_GNUC_UNUSED int argc, char **argv )
|
||||
{
|
||||
|
@ -895,6 +897,11 @@ int main ( int argc, char *argv[] )
|
|||
cleanup ();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if ( find_arg ( "-dump-config" ) >= 0 ) {
|
||||
rofi_dump_config ( rofi_theme );
|
||||
cleanup ();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
// Dump.
|
||||
// catch help request
|
||||
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
|
||||
|
|
|
@ -290,6 +290,14 @@ void rofi_theme_print ( ThemeWidget *widget )
|
|||
}
|
||||
}
|
||||
|
||||
void rofi_dump_config ( ThemeWidget *widget )
|
||||
{
|
||||
config_parse_dump_config ( );
|
||||
if ( widget != NULL ) {
|
||||
rofi_theme_print_index ( widget );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main lex parser.
|
||||
*/
|
||||
|
|
|
@ -513,6 +513,75 @@ void config_parse_xresource_dump ( void )
|
|||
}
|
||||
}
|
||||
|
||||
static void config_parse_dump_config_option ( XrmOption *option )
|
||||
{
|
||||
if ( option->type == xrm_Char ) {
|
||||
printf ( "/*" );
|
||||
}
|
||||
printf ( "\t%s: ", option->name );
|
||||
switch ( option->type )
|
||||
{
|
||||
case xrm_Number:
|
||||
printf ( "%u", *( option->value.num ) );
|
||||
break;
|
||||
case xrm_SNumber:
|
||||
printf ( "%i", *( option->value.snum ) );
|
||||
break;
|
||||
case xrm_String:
|
||||
if ( ( *( option->value.str ) ) != NULL ) {
|
||||
// TODO should this be escaped?
|
||||
printf ( "\"%s\"", *( option->value.str ) );
|
||||
}
|
||||
break;
|
||||
case xrm_Boolean:
|
||||
printf ( "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
|
||||
break;
|
||||
case xrm_Char:
|
||||
// TODO
|
||||
if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
|
||||
printf ( "'%c'", *( option->value.charc ) );
|
||||
}
|
||||
else {
|
||||
printf ( "'\\x%02X'", *( option->value.charc ) );
|
||||
}
|
||||
printf ( " /* unsupported */" );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
printf ( ";" );
|
||||
if ( option->type == xrm_Char ) {
|
||||
printf ( "*/" );
|
||||
}
|
||||
printf ( "\n" );
|
||||
}
|
||||
|
||||
void config_parse_dump_config ( void )
|
||||
{
|
||||
printf ( "configuration {\n" );
|
||||
|
||||
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
|
||||
for ( unsigned int i = 0; i < entries; ++i ) {
|
||||
// Skip duplicates.
|
||||
if ( ( i + 1 ) < entries ) {
|
||||
if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( xrmOptions[i].source != CONFIG_DEFAULT ) {
|
||||
config_parse_dump_config_option ( &( xrmOptions[i] ) );
|
||||
}
|
||||
}
|
||||
for ( unsigned int i = 0; i < num_extra_options; i++ ) {
|
||||
if ( extra_options[i].source != CONFIG_DEFAULT ) {
|
||||
config_parse_dump_config_option ( &( extra_options[i] ) );
|
||||
}
|
||||
}
|
||||
|
||||
printf ( "}\n" );
|
||||
}
|
||||
|
||||
static void print_option_string ( XrmOption *xo, int is_term )
|
||||
{
|
||||
int l = strlen ( xo->name );
|
||||
|
|
Loading…
Reference in a new issue