diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/annotate-snippets/src/stylesheets | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/annotate-snippets/src/stylesheets')
-rw-r--r-- | vendor/annotate-snippets/src/stylesheets/color.rs | 50 | ||||
-rw-r--r-- | vendor/annotate-snippets/src/stylesheets/mod.rs | 11 | ||||
-rw-r--r-- | vendor/annotate-snippets/src/stylesheets/no_color.rs | 31 |
3 files changed, 92 insertions, 0 deletions
diff --git a/vendor/annotate-snippets/src/stylesheets/color.rs b/vendor/annotate-snippets/src/stylesheets/color.rs new file mode 100644 index 000000000..024dd06f6 --- /dev/null +++ b/vendor/annotate-snippets/src/stylesheets/color.rs @@ -0,0 +1,50 @@ +use std::fmt::{self, Display}; + +use yansi_term::{Color::Fixed, Style as AnsiTermStyle}; + +use crate::formatter::style::{Style, StyleClass, Stylesheet}; + +struct AnsiTermStyleWrapper { + style: AnsiTermStyle, +} + +impl Style for AnsiTermStyleWrapper { + fn paint(&self, text: &str, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.style.paint(text).fmt(f) + } + + fn paint_fn<'a>( + &self, + c: Box<dyn FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result + 'a>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + self.style.paint_fn(c).fmt(f) + } + + fn bold(&self) -> Box<dyn Style> { + Box::new(AnsiTermStyleWrapper { style: self.style }) + } +} + +pub struct AnsiTermStylesheet; + +impl Stylesheet for AnsiTermStylesheet { + fn get_style(&self, class: StyleClass) -> Box<dyn Style> { + let ansi_term_style = match class { + StyleClass::Error => Fixed(9).bold(), + StyleClass::Warning => Fixed(11).bold(), + StyleClass::Info => Fixed(12).bold(), + StyleClass::Note => AnsiTermStyle::new().bold(), + StyleClass::Help => Fixed(14).bold(), + + StyleClass::LineNo => Fixed(12).bold(), + + StyleClass::Emphasis => AnsiTermStyle::new().bold(), + + StyleClass::None => AnsiTermStyle::new(), + }; + Box::new(AnsiTermStyleWrapper { + style: ansi_term_style, + }) + } +} diff --git a/vendor/annotate-snippets/src/stylesheets/mod.rs b/vendor/annotate-snippets/src/stylesheets/mod.rs new file mode 100644 index 000000000..4648852ad --- /dev/null +++ b/vendor/annotate-snippets/src/stylesheets/mod.rs @@ -0,0 +1,11 @@ +//! List of stylesheets +//! +//! The list depends on what optional dependencies the crate has been +//! compiled with. +//! +//! By default the `no_color` is available. If the crate gets compiled +//! with `ansi_term`, the `color` stylesheet is added. + +#[cfg(feature = "color")] +pub mod color; +pub mod no_color; diff --git a/vendor/annotate-snippets/src/stylesheets/no_color.rs b/vendor/annotate-snippets/src/stylesheets/no_color.rs new file mode 100644 index 000000000..21cb26955 --- /dev/null +++ b/vendor/annotate-snippets/src/stylesheets/no_color.rs @@ -0,0 +1,31 @@ +use std::fmt; + +use crate::formatter::style::{Style, StyleClass, Stylesheet}; + +pub struct NoOpStyle {} + +impl Style for NoOpStyle { + fn paint(&self, text: &str, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(text) + } + + fn paint_fn<'a>( + &self, + c: Box<dyn FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result + 'a>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + c(f) + } + + fn bold(&self) -> Box<dyn Style> { + Box::new(NoOpStyle {}) + } +} + +pub struct NoColorStylesheet; + +impl Stylesheet for NoColorStylesheet { + fn get_style(&self, _class: StyleClass) -> Box<dyn Style> { + Box::new(NoOpStyle {}) + } +} |