Trait ariadne::Fmt

source ·
pub trait Fmt: Sized {
    // Provided methods
    fn fg<C: Into<Option<Color>>>(self, color: C) -> Foreground<Self>
       where Self: Display { ... }
    fn bg<C: Into<Option<Color>>>(self, color: C) -> Background<Self>
       where Self: Display { ... }
}
Expand description

A trait used to add formatting attributes to displayable items.

If using the concolor feature, this trait assumes that the items are going to be printed to stderr. If you are printing to stdout, use the StdoutFmt trait instead.

Attributes specified through this trait are not composable (i.e: the behaviour of two nested attributes each with a conflicting attribute is left unspecified).

Provided Methods§

source

fn fg<C: Into<Option<Color>>>(self, color: C) -> Foreground<Self>where Self: Display,

Give this value the specified foreground colour.

Examples found in repository?
examples/multifile.rs (line 15)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut colors = ColorGenerator::new();

    // Generate some colours for each of our elements
    let a = colors.next();
    let b = colors.next();
    let c = colors.next();

    Report::build(ReportKind::Error, "b.tao", 10)
        .with_code(3)
        .with_message(format!("Cannot add types Nat and Str"))
        .with_label(Label::new(("b.tao", 10..14))
            .with_message(format!("This is of type {}", "Nat".fg(a)))
            .with_color(a))
        .with_label(Label::new(("b.tao", 17..20))
            .with_message(format!("This is of type {}", "Str".fg(b)))
            .with_color(b))
        .with_label(Label::new(("b.tao", 15..16))
            .with_message(format!(" {} and {} undergo addition here", "Nat".fg(a), "Str".fg(b)))
            .with_color(c)
            .with_order(10))
        .with_label(Label::new(("a.tao", 4..8))
            .with_message(format!("Original definition of {} is here", "five".fg(a)))
            .with_color(a))
        .with_note(format!("{} is a number and can only be added to other numbers", "Nat".fg(a)))
        .finish()
        .print(sources(vec![
            ("a.tao", include_str!("a.tao")),
            ("b.tao", include_str!("b.tao")),
        ]))
        .unwrap();
}
More examples
Hide additional examples
examples/multiline.rs (line 16)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let mut colors = ColorGenerator::new();

    // Generate & choose some colours for each of our elements
    let a = colors.next();
    let b = colors.next();
    let out = Color::Fixed(81);
    let out2= colors.next();

    Report::build(ReportKind::Error, "sample.tao", 12)
        .with_code(3)
        .with_message(format!("Incompatible types"))
        .with_label(Label::new(("sample.tao", 32..33))
            .with_message(format!("This is of type {}", "Nat".fg(a)))
            .with_color(a))
        .with_label(Label::new(("sample.tao", 42..45))
            .with_message(format!("This is of type {}", "Str".fg(b)))
            .with_color(b))
        .with_label(Label::new(("sample.tao", 11..48))
            .with_message(format!(
                "The values are outputs of this {} expression",
                "match".fg(out),
            ))
            .with_color(out))
        .with_label(Label::new(("sample.tao", 0..48))
            .with_message(format!(
                "The {} has a problem",
                "definition".fg(out2),
            ))
            .with_color(out2))
        .with_label(Label::new(("sample.tao", 50..76))
            .with_message(format!(
                "Usage of {} here",
                "definition".fg(out2),
            ))
            .with_color(out2))
        .with_note(format!("Outputs of {} expressions must coerce to the same type", "match".fg(out)))
        .finish()
        .print(("sample.tao", Source::from(include_str!("sample.tao"))))
        .unwrap();
}
source

fn bg<C: Into<Option<Color>>>(self, color: C) -> Background<Self>where Self: Display,

Give this value the specified background colour.

Implementors§

source§

impl<T: Display> Fmt for T