mirror of https://github.com/zkat/miette.git
Merge 2995233ab9 into b466948965
This commit is contained in:
commit
970461087c
|
|
@ -351,7 +351,8 @@ impl GraphicalReportHandler {
|
|||
opts = opts.word_splitter(word_splitter);
|
||||
}
|
||||
|
||||
writeln!(f, "{}", self.wrap(&diagnostic.to_string(), opts))?;
|
||||
let styled = diagnostic.style(self.theme.styles.title).to_string();
|
||||
writeln!(f, "{}", self.wrap(&styled, opts))?;
|
||||
|
||||
if !self.with_cause_chain {
|
||||
return Ok(());
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ Styles for various parts of graphical rendering for the
|
|||
*/
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ThemeStyles {
|
||||
/// Style to apply to the title.
|
||||
pub title: Style,
|
||||
/// Style to apply to things highlighted as "error".
|
||||
pub error: Style,
|
||||
/// Style to apply to things highlighted as "warning".
|
||||
|
|
@ -111,6 +113,7 @@ impl ThemeStyles {
|
|||
/// [Credit](http://terminal.sexy/#FRUV0NDQFRUVrEFCkKlZ9L91ap-1qnWfdbWq0NDQUFBQrEFCkKlZ9L91ap-1qnWfdbWq9fX1).
|
||||
pub fn rgb() -> Self {
|
||||
Self {
|
||||
title: style(),
|
||||
error: style().fg_rgb::<255, 30, 30>(),
|
||||
warning: style().fg_rgb::<244, 191, 117>(),
|
||||
advice: style().fg_rgb::<106, 159, 181>(),
|
||||
|
|
@ -128,6 +131,7 @@ impl ThemeStyles {
|
|||
/// ANSI color-based styles.
|
||||
pub fn ansi() -> Self {
|
||||
Self {
|
||||
title: style(),
|
||||
error: style().red(),
|
||||
warning: style().yellow(),
|
||||
advice: style().cyan(),
|
||||
|
|
@ -145,6 +149,7 @@ impl ThemeStyles {
|
|||
/// No styling. Just regular ol' monochrome.
|
||||
pub fn none() -> Self {
|
||||
Self {
|
||||
title: style(),
|
||||
error: style(),
|
||||
warning: style(),
|
||||
advice: style(),
|
||||
|
|
|
|||
|
|
@ -2030,6 +2030,24 @@ fn syntax_highlighter_on_real_file() {
|
|||
assert_eq!(expected, strip_ansi_escapes::strip_str(out));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_style_is_applied() {
|
||||
use miette::{GraphicalReportHandler, GraphicalTheme, Report, ThemeCharacters, ThemeStyles};
|
||||
|
||||
let theme = GraphicalTheme {
|
||||
characters: ThemeCharacters::unicode(),
|
||||
styles: ThemeStyles {
|
||||
title: owo_colors::Style::new().bold(),
|
||||
..ThemeStyles::none()
|
||||
},
|
||||
};
|
||||
let mut out = String::new();
|
||||
GraphicalReportHandler::new_themed(theme)
|
||||
.render_report(&mut out, Report::msg("hello").as_ref())
|
||||
.unwrap();
|
||||
assert_eq!(out, " × \u{1b}[1mhello\u{1b}[0m\n",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn triple_adjacent_highlight() -> Result<(), MietteError> {
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue