]>
git.proxmox.com Git - rustc.git/blob - vendor/annotate-snippets-0.6.1/src/formatter/style.rs
1 //! Set of structures required to implement a stylesheet for
2 //! [DisplayListFormatter](super::DisplayListFormatter).
4 //! In order to provide additional styling information for the
5 //! formatter, a structs can implement `Stylesheet` and `Style`
11 //! use annotate_snippets::formatter::style::{Stylesheet, StyleClass, Style};
13 //! struct HTMLStyle {
19 //! fn new(prefix: &str, postfix: &str) -> Self {
21 //! prefix: prefix.into(),
22 //! postfix: postfix.into()
27 //! impl Style for HTMLStyle {
28 //! fn paint(&self, text: &str) -> String {
29 //! format!("{}{}{}", self.prefix, text, self.postfix)
32 //! fn bold(&self) -> Box<Style> {
33 //! Box::new(HTMLStyle {
34 //! prefix: format!("{}<b>", self.prefix),
35 //! postfix: format!("</b>{}", self.postfix),
40 //! struct HTMLStylesheet {};
43 //! impl Stylesheet for HTMLStylesheet {
44 //! fn get_style(&self, class: StyleClass) -> Box<Style> {
45 //! let s = match class {
46 //! StyleClass::Error => HTMLStyle::new("<span style='color:red'>", "</span>"),
47 //! StyleClass::Warning => HTMLStyle::new("<span style='color:orange'>", "</span>"),
48 //! StyleClass::Info => HTMLStyle::new("<span style='color:yellow'>", "</span>"),
49 //! StyleClass::Note => HTMLStyle::new("<span style='color:blue'>", "</span>"),
50 //! StyleClass::Help => HTMLStyle::new("<span style='color:green'>", "</span>"),
51 //! StyleClass::LineNo => HTMLStyle::new("<strong>", "</strong>"),
52 //! StyleClass::Emphasis => HTMLStyle::new("<i>", "</i>"),
53 //! StyleClass::None => HTMLStyle::new("", ""),
60 /// StyleClass is a collection of named variants of style classes
61 /// that DisplayListFormatter uses.
63 /// Message indicating an error.
65 /// Message indicating a warning.
67 /// Message indicating an information.
69 /// Message indicating a note.
71 /// Message indicating a help.
74 /// Style for line numbers.
77 /// Parts of the text that are to be emphasised.
80 /// Parts of the text that are regular. Usually a no-op.
84 /// This trait implements a return value for the `Stylesheet::get_style`.
86 /// The method used by the DisplayListFormatter to style the message.
87 fn paint(&self, text
: &str) -> String
;
88 /// The method used by the DisplayListFormatter to display the message
90 fn bold(&self) -> Box
<dyn Style
>;
93 /// Trait to annotate structs that can provide `Style` implementations for
94 /// every `StyleClass` variant.
95 pub trait Stylesheet
{
96 /// Returns a `Style` implementer based on the requested `StyleClass` variant.
97 fn get_style(&self, class
: StyleClass
) -> Box
<dyn Style
>;