[X2Go-Commits] [x2goclient] 10/12: help.{cpp, h}: add a boolean terminal_output parameter to the pretty_print() function family.
git-admin at x2go.org
git-admin at x2go.org
Fri Apr 24 01:32:18 CEST 2015
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository x2goclient.
commit 3d5821802240c81a7bcfa263f94ae2b9af4435c1
Author: Mihai Moldovan <ionic at ionic.de>
Date: Fri Apr 24 01:08:39 2015 +0200
help.{cpp,h}: add a boolean terminal_output parameter to the pretty_print() function family.
Controls terminal width auto-detection and automatic printing to stderr.
---
debian/changelog | 3 +++
src/help.cpp | 30 +++++++++++++++++-------------
src/help.h | 12 +++++++++---
3 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 5b9ad08..e7a6516 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -307,6 +307,9 @@ x2goclient (4.0.4.0-0x2go1) UNRELEASED; urgency=low
split_long_line() function. Use this in pretty_print().
- help.cpp: simplify pretty_print() and make it also split lines for
non-terminal output or when the terminal width is unknown.
+ - help.{cpp,h}: add a boolean terminal_output parameter to the
+ pretty_print() function family. Controls terminal width auto-detection
+ and automatic printing to stderr.
[ Fernando Pedemonte ]
* New upstream release (4.0.4.0):
diff --git a/src/help.cpp b/src/help.cpp
index 6b95732..f5871be 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -181,11 +181,11 @@ help::string_split_t help::split_long_line (QString &line, std::ptrdiff_t max_le
return (ret);
}
-QString help::pretty_print () {
- return (help::pretty_print (help::build_data ()));
+QString help::pretty_print (bool terminal_output) {
+ return (help::pretty_print (help::build_data (), terminal_output));
}
-QString help::pretty_print (help::data_t data) {
+QString help::pretty_print (help::data_t data, bool terminal_output) {
QString ret = "";
QTextStream out (&ret);
out << data.first.join ("\n") << "\n";
@@ -199,19 +199,21 @@ QString help::pretty_print (help::data_t data) {
std::size_t terminal_cols = 0;
+ if (terminal_output) {
#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.srWindow.Left) + 1;
+ 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.srWindow.Left) + 1;
+ }
}
- }
#elif defined (Q_OS_UNIX)
- struct winsize terminal_internal;
- ioctl (0, TIOCGWINSZ, &terminal_internal);
- terminal_cols = terminal_internal.ws_col;
+ struct winsize terminal_internal;
+ ioctl (0, TIOCGWINSZ, &terminal_internal);
+ terminal_cols = terminal_internal.ws_col;
#endif
+ }
x2goDebug << "Terminal cols: " << terminal_cols << endl;
@@ -288,7 +290,9 @@ QString help::pretty_print (help::data_t data) {
}
}
- qCritical ().nospace () << qPrintable (ret);
+ if (terminal_output) {
+ qCritical ().nospace () << qPrintable (ret);
+ }
return (ret);
}
diff --git a/src/help.h b/src/help.h
index b6bfb21..3a9c24d 100644
--- a/src/help.h
+++ b/src/help.h
@@ -56,9 +56,15 @@ namespace help {
*/
string_split_t split_long_line (QString &line, std::ptrdiff_t max_length = 200);
- /* Prints a help_data_t structure. */
- QString pretty_print ();
- QString pretty_print (data_t data);
+ /*
+ * Returns a help_data_t structure as a QString.
+ * If terminal_output is true, the terminal width is probed for and the function
+ * family tries its best to adhere to the auto-detected width.
+ * Additionally, terminal_output controls whether the resulting string is
+ * printed to stderr or not.
+ */
+ QString pretty_print (bool terminal_output = true);
+ QString pretty_print (data_t data, bool terminal_output = true);
}
#endif /* !defined (HELP_H) */
--
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