From cb7b158172a8336778dc860795a1f2cdc0180356 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 11 May 2018 13:52:12 +0200 Subject: [PATCH] Add bold, italic and underline font styles --- src/terminal.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/terminal.rs b/src/terminal.rs index 01c2459..118bf3a 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -2,7 +2,7 @@ use std::fmt::Write; use ansi_term::Colour::{Fixed, RGB}; use ansi_term::Style; -use syntect::highlighting; +use syntect::highlighting::{self, FontStyle}; /// Approximate a 24 bit color value by a 8 bit ANSI code fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 { @@ -35,11 +35,23 @@ pub fn as_terminal_escaped( for &(ref style, text) in v.iter() { let style = if !colored { Style::default() - } else if true_color { - RGB(style.foreground.r, style.foreground.g, style.foreground.b).normal() } else { - let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b); - Fixed(ansi).normal() + let color = if true_color { + RGB(style.foreground.r, style.foreground.g, style.foreground.b) + } else { + let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b); + Fixed(ansi) + }; + + if style.font_style.contains(FontStyle::BOLD) { + color.bold() + } else if style.font_style.contains(FontStyle::UNDERLINE) { + color.underline() + } else if style.font_style.contains(FontStyle::ITALIC) { + color.italic() + } else { + color.normal() + } }; write!(s, "{}", style.paint(text)).unwrap();