Skip to content

Commit

Permalink
settings: move cli-specific settings to src/ui.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
chooglen committed Nov 17, 2022
1 parent 2a1118e commit ab4832c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 0 additions & 6 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,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 config(&self) -> &config::Config {
&self.config
}
Expand Down
12 changes: 11 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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() && atty::is(Stream::Stdout)
self.progress_indicator && atty::is(Stream::Stdout)
}

pub fn write(&mut self, text: &str) -> io::Result<()> {
Expand Down

0 comments on commit ab4832c

Please sign in to comment.