[][src]Function mdcat::highlighting::write_as_ansi

pub fn write_as_ansi<'a, W: Write, I: Iterator<Item = (Style, &'a str)>>(
    writer: &mut W,
    ansi: AnsiStyle,
    regions: I
) -> Result<(), Error>

Write regions as ANSI 8-bit coloured text.

We use this function to simplify syntax highlighting to 8-bit ANSI values which every theme provides. Contrary to 24 bit colours this gives us a good guarantee that highlighting works with any terminal colour theme, whether light or dark, and saves us all the hassle of mismatching colours.

We assume Solarized colours here: Solarized cleanly maps to 8-bit ANSI colours so we can safely map its RGB colour values back to ANSI colours. We do so for all accent colours, but leave "base*" colours alone: Base colours change depending on light or dark Solarized; to address both light and dark backgrounds we must map all base colours to the default terminal colours.

Furthermore we completely ignore any background colour settings, to avoid conflicts with the terminal colour themes.