diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-11-21 14:11:51 +0000 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2006-11-21 14:11:51 +0000 | 
| commit | a20d38574df43287123bc1e685c0fe3f11f81cc7 (patch) | |
| tree | 74133966a91dc278ad4dd53c7cee8888a9a595db /hardinfo2 | |
| parent | 0644d70519fa03be8f925911ace7ed18e40d1c0e (diff) | |
Add text mode progress indicators
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/shell.c | 61 | 
1 files changed, 37 insertions, 24 deletions
| diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 9713c4fc..84b7f3f2 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -101,14 +101,13 @@ void shell_action_set_property(const gchar *action_name,  void shell_action_set_enabled(const gchar *action_name, gboolean setting)  { -    GtkAction *action; +    if (params.gui_running) { +        GtkAction *action; -    if (!params.gui_running) -        return; -     -    action = gtk_action_group_get_action(shell->action_group, action_name); -    if (action) { -        gtk_action_set_sensitive(action, setting); +        action = gtk_action_group_get_action(shell->action_group, action_name); +        if (action) { +            gtk_action_set_sensitive(action, setting); +        }      }  } @@ -190,30 +189,44 @@ void shell_action_set_active(const gchar *action_name, gboolean setting)  void  shell_status_pulse(void)  { -    if (!params.gui_running) -        return; +    if (params.gui_running) { +        if (shell->_pulses++ == 20) { +            /* we're pulsing for some time, disable the interface and change the cursor +               to a hourglass */ +            shell_view_set_enabled(FALSE); +        } -    if (shell->_pulses++ == 20) { -        /* we're pulsing for some time, disable the interface and change the cursor -           to a hourglass */ -        shell_view_set_enabled(FALSE); +        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(shell->progress)); +        while (gtk_events_pending()) +            gtk_main_iteration(); +    } else { +        static gint counter = 0; +         +        fprintf(stderr, "\r%c\r", "|/-\\"[counter++ % 4]);      } - -    gtk_progress_bar_pulse(GTK_PROGRESS_BAR(shell->progress)); -    while (gtk_events_pending()) -	gtk_main_iteration();  }  void  shell_status_set_percentage(gint percentage)  { -    if (!params.gui_running) -        return; - -    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(shell->progress), -                                  (float)percentage/100.0); -    while (gtk_events_pending()) -	gtk_main_iteration(); +    if (params.gui_running) { +        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(shell->progress), +                                      (float)percentage/100.0); +        while (gtk_events_pending()) +            gtk_main_iteration(); +    } else { +        gint i, j = percentage / 10; +         +        if (j < 10) { +            gchar bar[] = "----------"; +            for (i = 0; i < j; i++)  +               bar[i] = '#'; + +            fprintf(stderr, "\r%3d%% %s\r", percentage, bar); +        } else { +            fprintf(stderr, "\033[2K"); +        } +    }  }  void | 
