mirror of https://github.com/zkat/miette.git
feat(graphical): add support for stylization on titles
This commit is contained in:
parent
df7bcfa17d
commit
2995233ab9
|
|
@ -351,7 +351,8 @@ impl GraphicalReportHandler {
|
||||||
opts = opts.word_splitter(word_splitter);
|
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 {
|
if !self.with_cause_chain {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,8 @@ Styles for various parts of graphical rendering for the
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ThemeStyles {
|
pub struct ThemeStyles {
|
||||||
|
/// Style to apply to the title.
|
||||||
|
pub title: Style,
|
||||||
/// Style to apply to things highlighted as "error".
|
/// Style to apply to things highlighted as "error".
|
||||||
pub error: Style,
|
pub error: Style,
|
||||||
/// Style to apply to things highlighted as "warning".
|
/// Style to apply to things highlighted as "warning".
|
||||||
|
|
@ -111,6 +113,7 @@ impl ThemeStyles {
|
||||||
/// [Credit](http://terminal.sexy/#FRUV0NDQFRUVrEFCkKlZ9L91ap-1qnWfdbWq0NDQUFBQrEFCkKlZ9L91ap-1qnWfdbWq9fX1).
|
/// [Credit](http://terminal.sexy/#FRUV0NDQFRUVrEFCkKlZ9L91ap-1qnWfdbWq0NDQUFBQrEFCkKlZ9L91ap-1qnWfdbWq9fX1).
|
||||||
pub fn rgb() -> Self {
|
pub fn rgb() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
title: style(),
|
||||||
error: style().fg_rgb::<255, 30, 30>(),
|
error: style().fg_rgb::<255, 30, 30>(),
|
||||||
warning: style().fg_rgb::<244, 191, 117>(),
|
warning: style().fg_rgb::<244, 191, 117>(),
|
||||||
advice: style().fg_rgb::<106, 159, 181>(),
|
advice: style().fg_rgb::<106, 159, 181>(),
|
||||||
|
|
@ -128,6 +131,7 @@ impl ThemeStyles {
|
||||||
/// ANSI color-based styles.
|
/// ANSI color-based styles.
|
||||||
pub fn ansi() -> Self {
|
pub fn ansi() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
title: style(),
|
||||||
error: style().red(),
|
error: style().red(),
|
||||||
warning: style().yellow(),
|
warning: style().yellow(),
|
||||||
advice: style().cyan(),
|
advice: style().cyan(),
|
||||||
|
|
@ -145,6 +149,7 @@ impl ThemeStyles {
|
||||||
/// No styling. Just regular ol' monochrome.
|
/// No styling. Just regular ol' monochrome.
|
||||||
pub fn none() -> Self {
|
pub fn none() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
title: style(),
|
||||||
error: style(),
|
error: style(),
|
||||||
warning: style(),
|
warning: style(),
|
||||||
advice: style(),
|
advice: style(),
|
||||||
|
|
|
||||||
|
|
@ -2030,6 +2030,24 @@ fn syntax_highlighter_on_real_file() {
|
||||||
assert_eq!(expected, strip_ansi_escapes::strip_str(out));
|
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]
|
#[test]
|
||||||
fn triple_adjacent_highlight() -> Result<(), MietteError> {
|
fn triple_adjacent_highlight() -> Result<(), MietteError> {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue