diff --git a/source/rofi.c b/source/rofi.c index dfb687de..a05a9a73 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -366,12 +366,22 @@ static void help_print_disabled_mode ( const char *mode ) } static void help_print_mode_not_found ( const char *mode ) { - int is_term = isatty ( fileno ( stdout ) ); - fprintf ( stderr, "Mode %s%s%s is not found.\n", - is_term ? color_red : "", mode, is_term ? color_reset : "" ); - fprintf ( stderr, "The following modi are known:\n" ); - print_list_of_modi ( is_term ); - printf ( "\n" ); + GString *str = g_string_new (""); + g_string_printf(str, "Mode %s is not found.\nThe following modi are known:\n", mode ); + for ( unsigned int i = 0; i < num_available_modi; i++ ) { + gboolean active = FALSE; + for ( unsigned int j = 0; j < num_modi; j++ ) { + if ( modi[j] == available_modi[i] ) { + active = TRUE; + break; + } + } + g_string_append_printf (str, " * %s%s\n", + active ? "+" : "", + available_modi[i]->name + ); + } + rofi_add_error_message ( str ); } static void help_print_no_arguments ( void ) { @@ -616,8 +626,6 @@ static gboolean setup_modi ( void ) for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { if ( add_mode ( token ) == -1 ) { help_print_mode_not_found ( token ); - g_free ( switcher_str ); - return TRUE; } } // Free string that was modified by strtok_r @@ -640,6 +648,25 @@ static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data ) g_main_loop_quit ( main_loop ); return G_SOURCE_CONTINUE; } +static void show_error_dialog () +{ + GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" ); + GList *iter = g_list_first ( list_of_error_msgs ); + int index = 0; + for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) { + GString *msg = (GString *) ( iter->data ); + g_string_append ( emesg, "\n\n" ); + g_string_append ( emesg, msg->str ); + index++; + } + if ( g_list_length ( iter ) > 1 ) { + g_string_append_printf ( emesg, "\nThere are %d more errors.", g_list_length ( iter ) - 1 ); + } + rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); + g_string_free ( emesg, TRUE ); + rofi_set_return_code ( EX_DATAERR ); + +} static gboolean startup ( G_GNUC_UNUSED gpointer data ) { @@ -662,21 +689,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) TICK_N ( "Config sanity check" ); if ( list_of_error_msgs != NULL ) { - GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" ); - GList *iter = g_list_first ( list_of_error_msgs ); - int index = 0; - for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) { - GString *msg = (GString *) ( iter->data ); - g_string_append ( emesg, "\n\n" ); - g_string_append ( emesg, msg->str ); - index++; - } - if ( g_list_length ( iter ) > 1 ) { - g_string_append_printf ( emesg, "\nThere are %d more errors.", g_list_length ( iter ) - 1 ); - } - rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); - g_string_free ( emesg, TRUE ); - rofi_set_return_code ( EX_DATAERR ); + show_error_dialog (); return G_SOURCE_REMOVE; } // Dmenu mode. @@ -715,7 +728,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) } else { help_print_mode_not_found ( sname ); - g_main_loop_quit ( main_loop ); + show_error_dialog (); return G_SOURCE_REMOVE; } }