[X2Go-Commits] [x2goclient] 08/12: help.cpp: simplify pretty_print() and make it also split lines for non-terminal output or when the terminal width is unknown.
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 dbaba2f174a6166accd77bd9d68ced414cf690d0
Author: Mihai Moldovan <ionic at ionic.de>
Date: Fri Apr 24 00:56:48 2015 +0200
help.cpp: simplify pretty_print() and make it also split lines for non-terminal output or when the terminal width is unknown.
---
debian/changelog | 2 ++
src/help.cpp | 54 +++++++++++++++++++++++++++---------------------------
2 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index dbe7eaf..5b9ad08 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -305,6 +305,8 @@ x2goclient (4.0.4.0-0x2go1) UNRELEASED; urgency=low
- help.cpp: typo fix for --git-info.
- help.{cpp,h}: provide string splitting logic as separate
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.
[ Fernando Pedemonte ]
* New upstream release (4.0.4.0):
diff --git a/src/help.cpp b/src/help.cpp
index 78bef9e..12a1264 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -249,41 +249,41 @@ QString help::pretty_print (help::data_t data) {
remaining = terminal_cols;
indent = 0;
}
+ }
- QString working_copy (*desc_split_it);
+ QString working_copy (*desc_split_it);
- while (!working_copy.isEmpty ()) {
- cur_len = working_copy.size ();
- x2goDebug << "Trying to fit a (remaining) description " << cur_len << " characters wide." << endl;
+ while (!working_copy.isEmpty ()) {
+ cur_len = working_copy.size ();
+ x2goDebug << "Trying to fit a (remaining) description " << cur_len << " characters wide." << endl;
- string_split_t string_split = split_long_line (working_copy, remaining);
- working_copy = string_split.first;
+ string_split_t string_split;
- /* Print potentially splitted line. */
- out << working_copy;
+ if (0 != terminal_cols) {
+ string_split = split_long_line (working_copy, remaining);
+ }
+ else {
+ /* For non-terminal printing (or if the width is unknown), use the default splitting length. */
+ string_split = split_long_line (working_copy);
+ }
- /* Continue with next chunk. */
- working_copy = string_split.second;;
+ /* Print potentially splitted line. */
+ working_copy = string_split.first;
+ out << working_copy;
- /* Print whitespace if the remainder string is non-empty. */
- if (!working_copy.isEmpty ()) {
- out << "\n";
- indent = terminal_cols - remaining;
- out << QString (" ").repeated (indent);
- }
- }
- }
- else {
- /* No idea what the terminal size is. Just print it all onto one line. */
- out << (*desc_split_it);
- }
+ /* Continue with next chunk. */
+ working_copy = string_split.second;;
- out << "\n";
+ out << "\n";
- /* Add whitespace if description shall continue on next line. */
- if ((desc_split_it + 1) != desc_split.constEnd ()) {
- indent = 2 + max_len + 4;
- out << QString (" ").repeated (indent);
+ /*
+ * Print whitespace if the remainder string is non-empty
+ * or printing shall continue on next line.
+ */
+ if ((!working_copy.isEmpty ()) || ((desc_split_it + 1) != desc_split.constEnd ())) {
+ indent = 2 + max_len + 4;
+ out << QString (" ").repeated (indent);
+ }
}
}
}
--
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