Patchwork D11762: rhg: Colored output is not supported

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2021, 5:43 p.m.
Message ID <differential-rev-PHID-DREV-hk767pggsiqyielzpgst-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50087/
State Superseded
Headers show

Comments

phabricator - Nov. 15, 2021, 5:43 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Fallback if it is requested explicitly.
  
  The default is documented as use color "whenever it seems possible".
  rhg proceeds without color in that case.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11762

AFFECTED FILES
  rust/rhg/src/main.rs

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -28,7 +28,7 @@ 
     repo: Result<&Repo, &NoRepoInCwdError>,
     config: &Config,
 ) -> Result<(), CommandError> {
-    check_unsupported(config)?;
+    check_unsupported(config, ui)?;
 
     let app = App::new("rhg")
         .global_setting(AppSettings::AllowInvalidUtf8)
@@ -615,7 +615,10 @@ 
     }
 }
 
-fn check_unsupported(config: &Config) -> Result<(), CommandError> {
+fn check_unsupported(
+    config: &Config,
+    ui: &ui::Ui,
+) -> Result<(), CommandError> {
     check_extensions(config)?;
 
     if std::env::var_os("HG_PENDING").is_some() {
@@ -632,5 +635,11 @@ 
         Err(CommandError::unsupported("[decode] config"))?
     }
 
+    if let Some(color) = config.get(b"ui", b"color") {
+        if (color == b"always" || color == b"debug") && !ui.plain() {
+            Err(CommandError::unsupported("colored output"))?
+        }
+    }
+
     Ok(())
 }