diff --git a/src/cli_util.rs b/src/cli_util.rs index fb623f49f..45d685c93 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1472,12 +1472,13 @@ impl ValueParserFactory for RevisionArg { pub fn create_ui() -> (Ui, Result<(), CommandError>) { // TODO: We need to do some argument parsing here, at least for things like // --config, and for reading user configs from the repo pointed to by -R. + let mut ui = Ui::new(); match read_config() { - Ok(user_settings) => (Ui::for_terminal(user_settings), Ok(())), - Err(err) => { - let ui = Ui::new(); - (ui, Err(CommandError::ConfigError(err.to_string()))) + Ok(user_settings) => { + ui.reset(user_settings); + (ui, Ok(())) } + Err(err) => (ui, Err(CommandError::ConfigError(err.to_string()))), } } diff --git a/src/ui.rs b/src/ui.rs index 9424e0be1..de76591a4 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -122,10 +122,7 @@ impl Default for Ui { impl Ui { pub fn new() -> Ui { - Self::for_terminal(UserSettings::from_config(crate::config::default_config())) - } - - pub fn for_terminal(settings: UserSettings) -> Ui { + let settings = UserSettings::from_config(crate::config::default_config()); let cwd = std::env::current_dir().unwrap(); let color = use_color(color_setting(&settings)); let progress_indicator = progress_indicator_setting(&settings); @@ -141,6 +138,14 @@ impl Ui { } } + pub fn reset(&mut self, settings: UserSettings) { + // TODO: maybe Ui shouldn't take ownership of UserSettings + self.color = use_color(color_setting(&settings)); + self.progress_indicator = progress_indicator_setting(&settings); + self.formatter_factory = FormatterFactory::prepare(&settings, self.color); + self.settings = settings; + } + /// Reconfigures the underlying outputs with the new color choice. pub fn reset_color(&mut self, choice: ColorChoice) { self.color = use_color(choice);