diff rust/rhg/src/ui.rs @ 48176:38deb65d4441

rhg: add ui.plain() and check it before showing relative paths in status Adds a very basic replica of `ui.plain()`. Differential Revision: https://phab.mercurial-scm.org/D10912
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 25 Jun 2021 15:00:08 +0530
parents 21d3b40b4c0e
children 47f2a82ae3e4
line wrap: on
line diff
--- a/rust/rhg/src/ui.rs	Tue Oct 05 18:10:04 2021 +0530
+++ b/rust/rhg/src/ui.rs	Fri Jun 25 15:00:08 2021 +0530
@@ -1,5 +1,6 @@
 use format_bytes::format_bytes;
 use std::borrow::Cow;
+use std::env;
 use std::io;
 use std::io::{ErrorKind, Write};
 
@@ -49,6 +50,25 @@
 
         stderr.flush().or_else(handle_stderr_error)
     }
+
+    /// is plain mode active
+    ///
+    /// Plain mode means that all configuration variables which affect
+    /// the behavior and output of Mercurial should be
+    /// ignored. Additionally, the output should be stable,
+    /// reproducible and suitable for use in scripts or applications.
+    ///
+    /// The only way to trigger plain mode is by setting either the
+    /// `HGPLAIN' or `HGPLAINEXCEPT' environment variables.
+    ///
+    /// The return value can either be
+    /// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
+    /// - False if feature is disabled by default and not included in HGPLAIN
+    /// - True otherwise
+    pub fn plain(&self) -> bool {
+        // TODO: add support for HGPLAINEXCEPT
+        env::var_os("HGPLAIN").is_some()
+    }
 }
 
 /// A buffered stdout writer for faster batch printing operations.