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)
|
.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 {
|
pub fn relative_timestamps(&self) -> bool {
|
||||||
self.config
|
self.config
|
||||||
.get_bool("ui.relative-timestamps")
|
.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 {
|
pub struct Ui {
|
||||||
color: bool,
|
color: bool,
|
||||||
|
progress_indicator: bool,
|
||||||
cwd: PathBuf,
|
cwd: PathBuf,
|
||||||
formatter_factory: FormatterFactory,
|
formatter_factory: FormatterFactory,
|
||||||
output: UiOutput,
|
output: UiOutput,
|
||||||
settings: UserSettings,
|
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)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub enum ColorChoice {
|
pub enum ColorChoice {
|
||||||
Always,
|
Always,
|
||||||
|
@ -88,11 +96,13 @@ impl Ui {
|
||||||
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));
|
||||||
|
let progress_indicator = progress_indicator_setting(&settings);
|
||||||
let formatter_factory = FormatterFactory::prepare(&settings, color);
|
let formatter_factory = FormatterFactory::prepare(&settings, color);
|
||||||
Ui {
|
Ui {
|
||||||
color,
|
color,
|
||||||
cwd,
|
cwd,
|
||||||
formatter_factory,
|
formatter_factory,
|
||||||
|
progress_indicator,
|
||||||
output: UiOutput::new_terminal(),
|
output: UiOutput::new_terminal(),
|
||||||
settings,
|
settings,
|
||||||
}
|
}
|
||||||
|
@ -151,7 +161,7 @@ impl Ui {
|
||||||
/// Whether continuous feedback should be displayed for long-running
|
/// Whether continuous feedback should be displayed for long-running
|
||||||
/// operations
|
/// operations
|
||||||
pub fn use_progress_indicator(&self) -> bool {
|
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<()> {
|
pub fn write(&mut self, text: &str) -> io::Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue