aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/terminal.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/terminal.hh')
-rw-r--r--src/libutil/terminal.hh24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/libutil/terminal.hh b/src/libutil/terminal.hh
index 2c422ecff..28c96c780 100644
--- a/src/libutil/terminal.hh
+++ b/src/libutil/terminal.hh
@@ -6,6 +6,26 @@
namespace nix {
+enum class StandardOutputStream {
+ Stdout = 1,
+ Stderr = 2,
+};
+
+/**
+ * Determine whether the output is a real terminal (i.e. not dumb, not a pipe).
+ *
+ * This is probably not what you want, you may want shouldANSI() or something
+ * more specific. Think about how the output should work with a pager or
+ * entirely non-interactive scripting use.
+ *
+ * The user may be redirecting the Lix output to a pager, but have stderr
+ * connected to a terminal. Think about where you are outputting the text when
+ * deciding whether to use STDERR_FILENO or STDOUT_FILENO.
+ *
+ * \param fileno file descriptor number to check if it is a tty
+ */
+bool isOutputARealTerminal(StandardOutputStream fileno);
+
/**
* Determine whether ANSI escape sequences are appropriate for the
* present output.
@@ -18,8 +38,10 @@ namespace nix {
* - CLICOLOR_FORCE or FORCE_COLOR set -> enable colour
* - The output is a tty; TERM != "dumb" -> enable colour
* - Otherwise -> disable colour
+ *
+ * \param fileno which file descriptor number to consider. Use the one you are outputting to
*/
-bool shouldANSI();
+bool shouldANSI(StandardOutputStream fileno = StandardOutputStream::Stderr);
/**
* Truncate a string to 'width' printable characters. If 'filterAll'