mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
cli: extract Ui::new() that creates ui with default config
Since ui object is needed to report read_config() error, it makes sense to create ui first without fallible user configuration. Ui::for_terminal() will be replaced with this function and ui.reset(read_config()?). Default::default() is also added to silence clippy. If we prefer, Ui::new() can be replaced with Ui::default().
This commit is contained in:
parent
48356817ba
commit
da95ae65be
2 changed files with 11 additions and 1 deletions
|
@ -1475,7 +1475,7 @@ pub fn create_ui() -> (Ui, Result<(), CommandError>) {
|
||||||
match read_config() {
|
match read_config() {
|
||||||
Ok(user_settings) => (Ui::for_terminal(user_settings), Ok(())),
|
Ok(user_settings) => (Ui::for_terminal(user_settings), Ok(())),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let ui = Ui::for_terminal(UserSettings::from_config(crate::config::default_config()));
|
let ui = Ui::new();
|
||||||
(ui, Err(CommandError::ConfigError(err.to_string())))
|
(ui, Err(CommandError::ConfigError(err.to_string())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/ui.rs
10
src/ui.rs
|
@ -114,7 +114,17 @@ fn pager_setting(settings: &UserSettings) -> FullCommandArgs {
|
||||||
.unwrap_or_else(|_| "less -FRX".into())
|
.unwrap_or_else(|_| "less -FRX".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Ui {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Ui {
|
impl Ui {
|
||||||
|
pub fn new() -> Ui {
|
||||||
|
Self::for_terminal(UserSettings::from_config(crate::config::default_config()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn for_terminal(settings: UserSettings) -> Ui {
|
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));
|
||||||
|
|
Loading…
Reference in a new issue