Change miette theme based on ANSI config (#5588)

* Change miette theme based on ANSI config

Use the base ansi colors to simplify the use of the terminal emulator
theming.
Turn of most eye-candy (including unicode) when using
`$config.use_ansi_coloring: false`

Addresses #5582

* Fix error test affected by changed styling
This commit is contained in:
Stefan Holderbach 2022-05-19 20:59:14 +02:00 committed by GitHub
parent 8fdc272bcc
commit 0d06b6259f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -181,7 +181,7 @@ fn errors_fetching_by_column_using_a_number() {
.contains("Data cannot be accessed with a cell path"),);
assert!(actual
.err
.contains(" record<0: string> doesn't support cell paths"),);
.contains("record<0: string> doesn't support cell paths"),);
})
}

View file

@ -1,5 +1,5 @@
use crate::engine::StateWorkingSet;
use miette::{LabeledSpan, MietteHandler, ReportHandler, Severity, SourceCode};
use miette::{LabeledSpan, MietteHandlerOpts, ReportHandler, Severity, SourceCode};
use thiserror::Error;
/// This error exists so that we can defer SourceCode handling. It simply
@ -20,7 +20,18 @@ pub fn format_error(
impl std::fmt::Debug for CliError<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
MietteHandler::default().debug(self, f)?;
let ansi_support = self.1.get_config().use_ansi_coloring;
let miette_handler = MietteHandlerOpts::new()
// For better support of terminal themes use the ANSI coloring
.rgb_colors(false)
.ansi_colors(true)
// If ansi support is disabled in the config disable the eye-candy
.color(ansi_support)
.unicode(ansi_support)
.terminal_links(ansi_support)
.build();
miette_handler.debug(self, f)?;
Ok(())
}
}