Handle SIGWINCH in APT::Progress-Fancy=1
authorMichael Vogt <mvo@debian.org>
Fri, 6 Dec 2013 14:54:12 +0000 (15:54 +0100)
committerMichael Vogt <mvo@debian.org>
Fri, 6 Dec 2013 14:54:12 +0000 (15:54 +0100)
apt-pkg/deb/dpkgpm.h
apt-pkg/install-progress.cc
apt-pkg/install-progress.h

index 06318d94f79693261f90c46c1368189afe78e28e..02e12a6d94e7204c4b2bc2c6605e1b8f93588ea1 100644 (file)
@@ -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
index 09b1bef9e6687a0a1179659d2f59e12b90e9070e..b82b7efdead7c82f0a853d2bb176a11d0edbbf84 100644 (file)
@@ -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";
index d721c6373193dd7510fc3680cf3e10c3f494a5af..4b7590983f6f47a75b684198f7252f069a47c6dd 100644 (file)
@@ -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,