Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/ui.rs @ 48731:f591b377375f
rhg: Make Ui::new falliable, add Ui::new_infallible
This allows propagating color configuration errors
Differential Revision: https://phab.mercurial-scm.org/D12165
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 10 Feb 2022 12:52:25 +0100 |
parents | 1aaf11e35aec |
children | 39c447e03dbc |
line wrap: on
line diff
--- a/rust/rhg/src/ui.rs Thu Feb 10 12:12:56 2022 +0100 +++ b/rust/rhg/src/ui.rs Thu Feb 10 12:52:25 2022 +0100 @@ -1,5 +1,6 @@ use format_bytes::format_bytes; use hg::config::Config; +use hg::errors::HgError; use hg::utils::files::get_bytes_from_os_string; use std::borrow::Cow; use std::env; @@ -22,7 +23,17 @@ /// The commandline user interface impl Ui { - pub fn new(_config: &Config) -> Self { + pub fn new(_config: &Config) -> Result<Self, HgError> { + Ok(Ui { + stdout: std::io::stdout(), + stderr: std::io::stderr(), + }) + } + + /// Default to no color if color configuration errors. + /// + /// Useful when we’re already handling another error. + pub fn new_infallible(_config: &Config) -> Self { Ui { stdout: std::io::stdout(), stderr: std::io::stderr(),