[X2Go-Commits] [x2goclient] 01/02: help.cpp: get terminal window sizes on UNIX-based and Windows operating systems.

git-admin at x2go.org git-admin at x2go.org
Wed Apr 22 09:31:50 CEST 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch bugfix/help-cmd
in repository x2goclient.

commit d9d7fbe6bdb09396991e5aff91e2babb21dbfd3d
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Apr 22 08:24:59 2015 +0200

    help.cpp: get terminal window sizes on UNIX-based and Windows operating systems.
---
 debian/changelog |    2 ++
 src/help.cpp     |   31 ++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 987f88f..ddbc5d0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -261,6 +261,8 @@ x2goclient (4.0.4.0-0x2go1) UNRELEASED; urgency=low
     - help.{cpp,h}: add skeleton for new help system.
     - help.{cpp,h}: add sanitizing helpers.
     - help.cpp: populate pretty_print: fetch max length of params.
+    - help.cpp: get terminal window sizes on UNIX-based and Windows operating
+      systems.
 
   [ Fernando Pedemonte ]
   * New upstream release (4.0.4.0):
diff --git a/src/help.cpp b/src/help.cpp
index 5201c12..831ad63 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -20,6 +20,15 @@
 #include <QCoreApplication>
 #include <QtDebug>
 #include <cstddef>
+
+/* For terminal size. */
+#ifdef Q_OS_WIN
+#include <windows.h>
+#elif defined (Q_OS_UNIX)
+#include <stdio.h>
+#include <sys/ioctl.h>
+#endif
+
 #include "help.h"
 #include "version.h"
 
@@ -89,5 +98,25 @@ void help::pretty_print (help::data_t data) {
     max_len = std::max (max_len, (*it).first.length ());
   }
 
-  std::size_t indent = 0;
+  std::size_t terminal_cols = 0;
+
+#ifdef Q_OS_WIN
+  CONSOLE_SCREEN_BUFFER_INFO terminal_internal;
+  HANDLE stderr_handle = GetStdHandle (STD_ERROR_HANDLE);
+  if (stderr_handle && (stderr_handle != INVALID_HANDLE_VALUE)) {
+    if (GetConsoleScreenBufferInfo (stderr_handle, &terminal_internal)) {
+      terminal_cols = (terminal_internal.srWindow.Right - terminal_internal.Left) + 1;
+    }
+  }
+#elif defined (Q_OS_UNIX)
+  struct winsize terminal_internal;
+  ioctl (0, TIOCGWINSZ, &terminal_internal);
+  terminal_cols = terminal_internal.ws_col;
+#endif
+
+  for (help::params_t::const_iterator it = data.second.constBegin (); it != data.second.constEnd (); ++it) {
+    out << "  ";
+    out << (*it).first;
+    out << QString (" ").repeated (max_len - (*it.length) + 4);
+  }
 }

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list