diff options
author | Jordan Galby <gravemind2a@gmail.com> | 2019-02-13 12:26:17 +0100 |
---|---|---|
committer | Liam Middlebrook <liammiddlebrook@gmail.com> | 2019-02-23 16:32:17 -0800 |
commit | a6491a9e667a3bf245cfa904cc891844269c1b19 (patch) | |
tree | bf4179f3b018811d1e55905355a1de724b4e815e | |
parent | 80b56d5be349fee22cdb406c01a6520842b52155 (diff) |
Disable word-wrapping when output is not a terminal
Issue:
When redirecting nvidia-settings output to a file or a pipe (for simple
recording, or scripting purposes), we don't want the output to change
depending on the current terminal width (TIOCGWINSZ).
Fix/Feature:
This change disables word-wrapping of `nv_msg`/`nv_*_msg` functions when
the output stream is not a terminal (not `isatty`).
PRE-Merge Build Fix from Liam Middlebrook <lmiddlebrook@nvidia.com>:
Add _GNU_SOURCE define for fileno
-rw-r--r-- | src/common-utils/msg.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/common-utils/msg.c b/src/common-utils/msg.c index 349c640..602bde1 100644 --- a/src/common-utils/msg.c +++ b/src/common-utils/msg.c @@ -20,6 +20,8 @@ * DEALINGS IN THE SOFTWARE. */ +#define _GNU_SOURCE // needed for fileno + #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -88,16 +90,21 @@ void reset_current_terminal_width(unsigned short new_val) static void format(FILE *stream, const char *prefix, const char *buf, const int whitespace) { - int i; - TextRows *t; + if (isatty(fileno(stream))) { + int i; + TextRows *t; - if (!__terminal_width) reset_current_terminal_width(0); + if (!__terminal_width) reset_current_terminal_width(0); - t = nv_format_text_rows(prefix, buf, __terminal_width, whitespace); + t = nv_format_text_rows(prefix, buf, __terminal_width, whitespace); - for (i = 0; i < t->n; i++) fprintf(stream, "%s\n", t->t[i]); + for (i = 0; i < t->n; i++) fprintf(stream, "%s\n", t->t[i]); - nv_free_text_rows(t); + nv_free_text_rows(t); + + } else { + fprintf(stream, "%s%s\n", prefix ? prefix : "", buf); + } } |