forked from mirrors/jj
cli: create default ui, then reconfigure with loaded user settings
This function will probably be used to apply settings loaded from .jj/repo/config.toml.
This commit is contained in:
parent
da95ae65be
commit
fa68a21bd1
2 changed files with 14 additions and 8 deletions
|
@ -1472,12 +1472,13 @@ impl ValueParserFactory for RevisionArg {
|
||||||
pub fn create_ui() -> (Ui, Result<(), CommandError>) {
|
pub fn create_ui() -> (Ui, Result<(), CommandError>) {
|
||||||
// TODO: We need to do some argument parsing here, at least for things like
|
// 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.
|
// --config, and for reading user configs from the repo pointed to by -R.
|
||||||
|
let mut ui = Ui::new();
|
||||||
match read_config() {
|
match read_config() {
|
||||||
Ok(user_settings) => (Ui::for_terminal(user_settings), Ok(())),
|
Ok(user_settings) => {
|
||||||
Err(err) => {
|
ui.reset(user_settings);
|
||||||
let ui = Ui::new();
|
(ui, Ok(()))
|
||||||
(ui, Err(CommandError::ConfigError(err.to_string())))
|
|
||||||
}
|
}
|
||||||
|
Err(err) => (ui, Err(CommandError::ConfigError(err.to_string()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/ui.rs
13
src/ui.rs
|
@ -122,10 +122,7 @@ impl Default for Ui {
|
||||||
|
|
||||||
impl Ui {
|
impl Ui {
|
||||||
pub fn new() -> Ui {
|
pub fn new() -> Ui {
|
||||||
Self::for_terminal(UserSettings::from_config(crate::config::default_config()))
|
let settings = UserSettings::from_config(crate::config::default_config());
|
||||||
}
|
|
||||||
|
|
||||||
pub fn for_terminal(settings: UserSettings) -> Ui {
|
|
||||||
let cwd = std::env::current_dir().unwrap();
|
let cwd = std::env::current_dir().unwrap();
|
||||||
let color = use_color(color_setting(&settings));
|
let color = use_color(color_setting(&settings));
|
||||||
let progress_indicator = progress_indicator_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.
|
/// Reconfigures the underlying outputs with the new color choice.
|
||||||
pub fn reset_color(&mut self, choice: ColorChoice) {
|
pub fn reset_color(&mut self, choice: ColorChoice) {
|
||||||
self.color = use_color(choice);
|
self.color = use_color(choice);
|
||||||
|
|
Loading…
Reference in a new issue