mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
ui: add color field
This gives us a convenient way to read the color setting when handling errors from clap.
This commit is contained in:
parent
38ee349cc2
commit
a52c32adef
1 changed files with 9 additions and 3 deletions
12
src/ui.rs
12
src/ui.rs
|
@ -23,6 +23,7 @@ use jujutsu_lib::settings::UserSettings;
|
|||
use crate::formatter::{Formatter, FormatterFactory};
|
||||
|
||||
pub struct Ui {
|
||||
color: bool,
|
||||
cwd: PathBuf,
|
||||
formatter_factory: FormatterFactory,
|
||||
output_pair: UiOutputPair,
|
||||
|
@ -78,6 +79,7 @@ impl Ui {
|
|||
let color = use_color(color_setting(&settings));
|
||||
let formatter_factory = FormatterFactory::prepare(&settings, color);
|
||||
Ui {
|
||||
color,
|
||||
cwd,
|
||||
formatter_factory,
|
||||
output_pair: UiOutputPair::Terminal {
|
||||
|
@ -90,12 +92,16 @@ impl Ui {
|
|||
|
||||
/// Reconfigures the underlying outputs with the new color choice.
|
||||
pub fn reset_color(&mut self, choice: ColorChoice) {
|
||||
let color = use_color(choice);
|
||||
if self.formatter_factory.is_color() != color {
|
||||
self.formatter_factory = FormatterFactory::prepare(&self.settings, color);
|
||||
self.color = use_color(choice);
|
||||
if self.formatter_factory.is_color() != self.color {
|
||||
self.formatter_factory = FormatterFactory::prepare(&self.settings, self.color);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color(&self) -> bool {
|
||||
self.color
|
||||
}
|
||||
|
||||
pub fn cwd(&self) -> &Path {
|
||||
&self.cwd
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue