mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 08:53:16 +00:00
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>) {
|
||||
// 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()))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
src/ui.rs
13
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);
|
||||
|
|
Loading…
Reference in a new issue