diff --git a/client/pk-console.c b/client/pk-console.c index 0759767f7..8052e411f 100644 --- a/client/pk-console.c +++ b/client/pk-console.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #define PK_EXIT_CODE_SYNTAX_INVALID 3 #define PK_EXIT_CODE_FILE_NOT_FOUND 4 @@ -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, @@ -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");