summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2014-04-14 17:12:09 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2014-04-14 17:12:09 +0200
commit76bd63e2dc6ac5aaaf7f2cc98c2a83ab88ccc46c (patch)
treea313d790f914d36b6707f72f6995e06c015b29a3 /apt-pkg
parentcbc9ec23b0fb551f20f4fd8ca46d98f59b5666bc (diff)
force fancy progressbar redraw on window size change
We always reacted on the size change, but the bar is only redraw if the precentage changes, which can take quiet a while in big upgrades, so with a bit of refactoring we can now call for a redraw immediate to fix this. This refactor also helps in avoiding obscure pitfalls clangs static analyser was complaining about (namely failure of ioctl resulting in garbage values in the struct).
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/install-progress.cc35
-rw-r--r--apt-pkg/install-progress.h3
2 files changed, 26 insertions, 12 deletions
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index 8bb587f67..cf6c85912 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -256,14 +256,14 @@ PackageManagerFancy::TermSize
PackageManagerFancy::GetTerminalSize()
{
struct winsize win;
- PackageManagerFancy::TermSize s;
+ PackageManagerFancy::TermSize s = { 0, 0 };
// FIXME: get from "child_pty" instead?
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
return s;
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
- std::cerr << "GetTerminalSize: " << win.ws_row << std::endl;
+ std::cerr << "GetTerminalSize: " << win.ws_row << " x " << win.ws_col << std::endl;
s.rows = win.ws_row;
s.columns = win.ws_col;
@@ -275,6 +275,9 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
std::cerr << "SetupTerminalScrollArea: " << nr_rows << std::endl;
+ if (unlikely(nr_rows <= 1))
+ return;
+
// scroll down a bit to avoid visual glitch when the screen
// area shrinks by one row
std::cout << "\n";
@@ -296,28 +299,30 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
// setup tty size to ensure xterm/linux console are working properly too
// see bug #731738
struct winsize win;
- ioctl(child_pty, TIOCGWINSZ, (char *)&win);
- win.ws_row = nr_rows - 1;
- ioctl(child_pty, TIOCSWINSZ, (char *)&win);
+ if (ioctl(child_pty, TIOCGWINSZ, (char *)&win) != -1)
+ {
+ win.ws_row = nr_rows - 1;
+ ioctl(child_pty, TIOCSWINSZ, (char *)&win);
+ }
}
void PackageManagerFancy::HandleSIGWINCH(int)
{
- int nr_terminal_rows = GetTerminalSize().rows;
+ int const nr_terminal_rows = GetTerminalSize().rows;
SetupTerminalScrollArea(nr_terminal_rows);
+ DrawStatusLine();
}
void PackageManagerFancy::Start(int a_child_pty)
{
child_pty = a_child_pty;
- int nr_terminal_rows = GetTerminalSize().rows;
- if (nr_terminal_rows > 0)
- SetupTerminalScrollArea(nr_terminal_rows);
+ int const nr_terminal_rows = GetTerminalSize().rows;
+ SetupTerminalScrollArea(nr_terminal_rows);
}
void PackageManagerFancy::Stop()
{
- int nr_terminal_rows = GetTerminalSize().rows;
+ int const nr_terminal_rows = GetTerminalSize().rows;
if (nr_terminal_rows > 0)
{
SetupTerminalScrollArea(nr_terminal_rows + 1);
@@ -358,7 +363,13 @@ bool PackageManagerFancy::StatusChanged(std::string PackageName,
HumanReadableAction))
return false;
- PackageManagerFancy::TermSize size = GetTerminalSize();
+ return DrawStatusLine();
+}
+bool PackageManagerFancy::DrawStatusLine()
+{
+ PackageManagerFancy::TermSize const size = GetTerminalSize();
+ if (unlikely(size.rows < 1 || size.columns < 1))
+ return false;
static std::string save_cursor = "\033[s";
static std::string restore_cursor = "\033[u";
@@ -388,7 +399,7 @@ bool PackageManagerFancy::StatusChanged(std::string PackageName,
{
int padding = 4;
float progressbar_size = size.columns - padding - progress_str.size();
- float current_percent = (float)StepsDone/(float)TotalSteps;
+ float current_percent = percentage / 100.0;
std::cout << " "
<< GetTextProgressStr(current_percent, progressbar_size)
<< " ";
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index 112b034fb..5d1a20e9b 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -1,6 +1,8 @@
#ifndef PKGLIB_IPROGRESS_H
#define PKGLIB_IPROGRESS_H
+#include <apt-pkg/macros.h>
+
#include <string>
#include <unistd.h>
#include <signal.h>
@@ -120,6 +122,7 @@ namespace Progress {
private:
static void staticSIGWINCH(int);
static std::vector<PackageManagerFancy*> instances;
+ APT_HIDDEN bool DrawStatusLine();
protected:
void SetupTerminalScrollArea(int nr_rows);