Commit a6491a9e authored by Jordan Galby's avatar Jordan Galby Committed by Liam Middlebrook

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
parent 80b56d5b
......@@ -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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment