@@ -2,7 +2,7 @@ use std::fmt::Write;
22
33use ansi_term::Colour::{Fixed, RGB};
44use ansi_term::Style;
5−use syntect::highlighting;
5+use syntect::highlighting::{self, FontStyle};
66
77/// Approximate a 24 bit color value by a 8 bit ANSI code
88fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
@@ -27,18 +27,31 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
2727}
2828
2929pub fn as_terminal_escaped(
30− color: highlighting::Style,
30+ style: highlighting::Style,
3131 text: &str,
3232 true_color: bool,
3333 colored: bool,
3434) -> String {
35+
3536 let style = if !colored {
3637 Style::default()
37− } else if true_color {
38− RGB(color.foreground.r, color.foreground.g, color.foreground.b).normal()
3938 } else {
40− let ansi = rgb2ansi(color.foreground.r, color.foreground.g, color.foreground.b);
41− Fixed(ansi).normal()
39+ let color = if true_color {
40+ RGB(style.foreground.r, style.foreground.g, style.foreground.b)
41+ } else {
42+ let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
43+ Fixed(ansi)
44+ };
45+
46+ if style.font_style.contains(FontStyle::BOLD) {
47+ color.bold()
48+ } else if style.font_style.contains(FontStyle::UNDERLINE) {
49+ color.underline()
50+ } else if style.font_style.contains(FontStyle::ITALIC) {
51+ color.italic()
52+ } else {
53+ color.normal()
54+ }
4255 };
4356
4457 let mut s: String = String::new();