summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-12-06 15:54:12 +0100
committerMichael Vogt <mvo@debian.org>2013-12-06 15:54:12 +0100
commite96e4e9cef3a0137b789117f72a93a8e9106562e (patch)
tree36210c2be37bce2f14fe4d4fcb1eaafb06767673
parent7d15eeef6e61d9a02efcad2dc704f22df4276d9b (diff)
Handle SIGWINCH in APT::Progress-Fancy=1
-rw-r--r--apt-pkg/deb/dpkgpm.h1
-rw-r--r--apt-pkg/install-progress.cc32
-rw-r--r--apt-pkg/install-progress.h9
3 files changed, 31 insertions, 11 deletions
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index 06318d94f..02e12a6d9 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -89,7 +89,6 @@ class pkgDPkgPM : public pkgPackageManager
const std::string &short_pkgname);
// Terminal progress
- void SetupTerminalScrollArea(int nr_scrolled_rows);
void SendTerminalProgress(float percentage);
// apport integration
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index 09b1bef9e..b82b7efde 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -10,6 +10,7 @@
#include <sstream>
#include <fcntl.h>
+
namespace APT {
namespace Progress {
@@ -221,6 +222,14 @@ bool PackageManagerProgressDeb822Fd::StatusChanged(std::string PackageName,
return true;
}
+int PackageManagerFancy::GetNumberTerminalRows()
+{
+ struct winsize win;
+ if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
+ return -1;
+
+ return win.ws_row;
+}
void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
{
@@ -248,23 +257,32 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
}
PackageManagerFancy::PackageManagerFancy()
- : nr_terminal_rows(-1)
{
- struct winsize win;
- if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) == 0)
- {
- nr_terminal_rows = win.ws_row;
- }
+ // setup terminal size
+ old_SIGWINCH = signal(SIGWINCH, HandleSIGWINCH);
+}
+
+PackageManagerFancy::~PackageManagerFancy()
+{
+ signal(SIGWINCH, old_SIGWINCH);
+}
+
+void PackageManagerFancy::HandleSIGWINCH(int)
+{
+ int nr_terminal_rows = GetNumberTerminalRows();
+ SetupTerminalScrollArea(nr_terminal_rows);
}
void PackageManagerFancy::Start()
{
+ int nr_terminal_rows = GetNumberTerminalRows();
if (nr_terminal_rows > 0)
SetupTerminalScrollArea(nr_terminal_rows);
}
void PackageManagerFancy::Stop()
{
+ int nr_terminal_rows = GetNumberTerminalRows();
if (nr_terminal_rows > 0)
{
SetupTerminalScrollArea(nr_terminal_rows + 1);
@@ -284,7 +302,7 @@ bool PackageManagerFancy::StatusChanged(std::string PackageName,
HumanReadableAction))
return false;
- int row = nr_terminal_rows;
+ int row = GetNumberTerminalRows();
static string save_cursor = "\033[s";
static string restore_cursor = "\033[u";
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index d721c6373..4b7590983 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -3,7 +3,7 @@
#include <string>
#include <unistd.h>
-
+#include <signal.h>
namespace APT {
namespace Progress {
@@ -117,11 +117,14 @@ namespace Progress {
class PackageManagerFancy : public PackageManager
{
protected:
- int nr_terminal_rows;
- void SetupTerminalScrollArea(int nr_rows);
+ static void SetupTerminalScrollArea(int nr_rows);
+ static int GetNumberTerminalRows();
+ static void HandleSIGWINCH(int);
+ sighandler_t old_SIGWINCH;
public:
PackageManagerFancy();
+ ~PackageManagerFancy();
virtual void Start();
virtual void Stop();
virtual bool StatusChanged(std::string PackageName,