commit: b4e37543f21958c5e5981c2b3694213d150d5bcd
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 13 10:51:56 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jun 13 10:51:56 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b4e37543
main: disable word wrapping when stdout is not a terminal
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
main.c | 5 +++--
qmanifest.c | 2 +-
quse.c | 8 ++++++--
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/main.c b/main.c
index f5f7b57..f9dfb6d 100644
--- a/main.c
+++ b/main.c
@@ -778,7 +778,6 @@ int main(int argc, char **argv)
struct winsize winsz;
ioctl(0, TIOCGWINSZ, &winsz);
- if (winsz.ws_col > 0)
twidth = winsz.ws_col > 0 ? (int)winsz.ws_col : 80;
warnout = stderr;
@@ -790,8 +789,10 @@ int main(int argc, char **argv)
textdomain(argv0);
if (fstat(fileno(stdout), &st) != -1)
- if (!isatty(fileno(stdout)))
+ if (!isatty(fileno(stdout))) {
no_colors();
+ twidth = 0;
+ }
if ((getenv("TERM") == NULL) || (strcmp(getenv("TERM"), "dumb") == 0))
no_colors();
diff --git a/qmanifest.c b/qmanifest.c
index 7ca2b40..21254c3 100644
--- a/qmanifest.c
+++ b/qmanifest.c
@@ -1505,7 +1505,7 @@ format_line(const char *pfx, const char *msg)
if (*pfx == '-') {
fprintf(stdout, "%s%s%s%s\n", pfx, RED, msg, NORM);
} else {
- if (!verbose && msglen > (size_t)twidth) {
+ if (!verbose && twidth > 0 && msglen > (size_t)twidth) {
int to_remove = 3 + (msglen - twidth);
int first_half = msglen / 2 - to_remove / 2;
int remainder = msglen / 2 + (to_remove + 1) / 2;
diff --git a/quse.c b/quse.c
index f1d52ae..8a9f78a 100644
--- a/quse.c
+++ b/quse.c
@@ -600,8 +600,12 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
quse_search_profiles_desc(portdirfd,
&us);
/* calculate available space in the terminal to print
- * descriptions */
- len = twidth - maxlen - 2 - 1 - 2;
+ * descriptions, assume this makes sense from 10 chars
*/
+ if (twidth > maxlen + 2 + 1 + 2 + 10) {
+ len = twidth - maxlen - 2 - 1 - 2;
+ } else {
+ len = 0;
+ }
for (i = 0; i < cnt; i++) {
match = use != NULL && contains_set(us.argv[i],
use);