forked from mirrors/jj
settings: move cli-specific settings to src/ui.rs
This commit is contained in:
parent
d622656deb
commit
f4f0fbbd5d
2 changed files with 11 additions and 7 deletions
|
@ -137,12 +137,6 @@ impl UserSettings {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn use_progress_indicator(&self) -> bool {
|
||||
self.config
|
||||
.get_bool("ui.progress-indicator")
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
pub fn relative_timestamps(&self) -> bool {
|
||||
self.config
|
||||
.get_bool("ui.relative-timestamps")
|
||||
|
|
12
src/ui.rs
12
src/ui.rs
|
@ -24,12 +24,20 @@ use crate::formatter::{Formatter, FormatterFactory};
|
|||
|
||||
pub struct Ui {
|
||||
color: bool,
|
||||
progress_indicator: bool,
|
||||
cwd: PathBuf,
|
||||
formatter_factory: FormatterFactory,
|
||||
output: UiOutput,
|
||||
settings: UserSettings,
|
||||
}
|
||||
|
||||
fn progress_indicator_setting(settings: &UserSettings) -> bool {
|
||||
settings
|
||||
.config()
|
||||
.get_bool("ui.progress-indicator")
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum ColorChoice {
|
||||
Always,
|
||||
|
@ -88,11 +96,13 @@ impl Ui {
|
|||
pub fn for_terminal(settings: UserSettings) -> Ui {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let color = use_color(color_setting(&settings));
|
||||
let progress_indicator = progress_indicator_setting(&settings);
|
||||
let formatter_factory = FormatterFactory::prepare(&settings, color);
|
||||
Ui {
|
||||
color,
|
||||
cwd,
|
||||
formatter_factory,
|
||||
progress_indicator,
|
||||
output: UiOutput::new_terminal(),
|
||||
settings,
|
||||
}
|
||||
|
@ -151,7 +161,7 @@ impl Ui {
|
|||
/// Whether continuous feedback should be displayed for long-running
|
||||
/// operations
|
||||
pub fn use_progress_indicator(&self) -> bool {
|
||||
self.settings().use_progress_indicator() && io::stdout().is_tty()
|
||||
self.progress_indicator && io::stdout().is_tty()
|
||||
}
|
||||
|
||||
pub fn write(&mut self, text: &str) -> io::Result<()> {
|
||||
|
|
Loading…
Reference in a new issue