html2text/
ansi_colours.rs

1//! Convenience helper for producing coloured terminal output.
2//!
3//! This optional helper applies terminal colours (or other effects which
4//! can be achieved using inline characters sent to the terminal such as
5//! underlining in some terminals).
6
7use crate::RichAnnotation;
8use std::io;
9
10/// Reads HTML from `input`, and returns text wrapped to `width` columns.
11///
12/// The text is returned as a `Vec<TaggedLine<_>>`; the annotations are vectors
13/// of `RichAnnotation`.  The "outer" annotation comes first in the `Vec`.
14///
15/// The function `colour_map` is given a slice of `RichAnnotation` and should
16/// return a pair of static strings which should be inserted before/after a text
17/// span with that annotation; for example a string which sets text colour
18/// and a string which sets the colour back to the default.
19pub fn from_read_coloured<R, FMap>(
20    input: R,
21    width: usize,
22    colour_map: FMap,
23) -> Result<String, crate::Error>
24where
25    R: io::Read,
26    FMap: Fn(&[RichAnnotation], &str) -> String,
27{
28    super::config::rich().coloured(input, width, colour_map)
29}