Skip to content

Commit

Permalink
* Shrink the progress bar to fit when run in small spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
deftdawg authored and hughsie committed Oct 23, 2019
1 parent 670c002 commit 8a549c9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions client/pk-console.c
Expand Up @@ -32,6 +32,8 @@
#include <sys/types.h>
#include <pwd.h>
#include <locale.h>
#include <sys/ioctl.h>
#include <sys/param.h>

#define PK_EXIT_CODE_SYNTAX_INVALID 3
#define PK_EXIT_CODE_FILE_NOT_FOUND 4
Expand Down Expand Up @@ -1601,6 +1603,9 @@ main (int argc, char *argv[])
g_autofree gchar *filter = NULL;
g_autofree gchar *options_help = NULL;
g_autofree gchar *summary = NULL;
guint bar_padding = 30;
guint bar_size = 25;
struct winsize w;

const GOptionEntry options[] = {
{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
Expand Down Expand Up @@ -1652,9 +1657,16 @@ main (int argc, char *argv[])
ctx,
NULL);

/* Shrink the progresbar to fit in small spaces i.e. termux, small tmux panes, large font terminals */
/* If ioctl reports back and the terminal is small, shrink to fit as best we can */
if (!ioctl (STDOUT_FILENO, TIOCGWINSZ, &w)) {
bar_padding = MAX (1, MIN ( (w.ws_col / 2), bar_padding));
bar_size = MAX (0, MIN (w.ws_col - (bar_padding + 11), bar_size));
}

ctx->progressbar = pk_progress_bar_new ();
pk_progress_bar_set_size (ctx->progressbar, 25);
pk_progress_bar_set_padding (ctx->progressbar, 30);
pk_progress_bar_set_size (ctx->progressbar, bar_size);
pk_progress_bar_set_padding (ctx->progressbar, bar_padding);

ctx->cancellable = g_cancellable_new ();
context = g_option_context_new ("PackageKit Console Program");
Expand Down

0 comments on commit 8a549c9

Please sign in to comment.