Skip to content

Commit 3e5ed9c

Browse files
authored
Merge pull request #12 from joshtriplett/yansi-bright
fix(yansi): Handle Bright foreground colors as bold
2 parents 5529603 + ab3e25a commit 3e5ed9c

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

crates/yansi/src/lib.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ impl Ext for anstyle::Style {
1515
}
1616

1717
pub fn to_yansi_style(style: anstyle::Style) -> yansi::Style {
18-
let fg = style
18+
let (fg, fg_bold) = style
1919
.get_fg_color()
20-
.map(to_yansi_color)
21-
.unwrap_or(yansi::Color::Unset);
20+
.map(to_yansi_color_with_bold)
21+
.unwrap_or((yansi::Color::Unset, false));
2222
let bg = style
2323
.get_bg_color()
2424
.map(to_yansi_color)
2525
.unwrap_or(yansi::Color::Unset);
2626
let effects = style.get_effects();
2727

2828
let mut style = yansi::Style::new(fg).bg(bg);
29-
if effects.contains(anstyle::Effects::BOLD) {
29+
if effects.contains(anstyle::Effects::BOLD) || fg_bold {
3030
style = style.bold();
3131
}
3232
if effects.contains(anstyle::Effects::DIMMED) {
@@ -54,31 +54,35 @@ pub fn to_yansi_style(style: anstyle::Style) -> yansi::Style {
5454
}
5555

5656
pub fn to_yansi_color(color: anstyle::Color) -> yansi::Color {
57+
to_yansi_color_with_bold(color).0
58+
}
59+
60+
fn to_yansi_color_with_bold(color: anstyle::Color) -> (yansi::Color, bool) {
5761
match color {
5862
anstyle::Color::Ansi(ansi) => ansi_to_yansi_color(ansi),
59-
anstyle::Color::XTerm(xterm) => xterm_to_yansi_color(xterm),
60-
anstyle::Color::Rgb(rgb) => rgb_to_yansi_color(rgb),
63+
anstyle::Color::XTerm(xterm) => (xterm_to_yansi_color(xterm), false),
64+
anstyle::Color::Rgb(rgb) => (rgb_to_yansi_color(rgb), false),
6165
}
6266
}
6367

64-
fn ansi_to_yansi_color(color: anstyle::AnsiColor) -> yansi::Color {
68+
fn ansi_to_yansi_color(color: anstyle::AnsiColor) -> (yansi::Color, bool) {
6569
match color {
66-
anstyle::AnsiColor::Black => yansi::Color::Black,
67-
anstyle::AnsiColor::Red => yansi::Color::Red,
68-
anstyle::AnsiColor::Green => yansi::Color::Green,
69-
anstyle::AnsiColor::Yellow => yansi::Color::Yellow,
70-
anstyle::AnsiColor::Blue => yansi::Color::Blue,
71-
anstyle::AnsiColor::Magenta => yansi::Color::Magenta,
72-
anstyle::AnsiColor::Cyan => yansi::Color::Cyan,
73-
anstyle::AnsiColor::White => yansi::Color::White,
74-
anstyle::AnsiColor::BrightBlack => yansi::Color::Black,
75-
anstyle::AnsiColor::BrightRed => yansi::Color::Red,
76-
anstyle::AnsiColor::BrightGreen => yansi::Color::Green,
77-
anstyle::AnsiColor::BrightYellow => yansi::Color::Yellow,
78-
anstyle::AnsiColor::BrightBlue => yansi::Color::Black,
79-
anstyle::AnsiColor::BrightMagenta => yansi::Color::Magenta,
80-
anstyle::AnsiColor::BrightCyan => yansi::Color::Cyan,
81-
anstyle::AnsiColor::BrightWhite => yansi::Color::White,
70+
anstyle::AnsiColor::Black => (yansi::Color::Black, false),
71+
anstyle::AnsiColor::Red => (yansi::Color::Red, false),
72+
anstyle::AnsiColor::Green => (yansi::Color::Green, false),
73+
anstyle::AnsiColor::Yellow => (yansi::Color::Yellow, false),
74+
anstyle::AnsiColor::Blue => (yansi::Color::Blue, false),
75+
anstyle::AnsiColor::Magenta => (yansi::Color::Magenta, false),
76+
anstyle::AnsiColor::Cyan => (yansi::Color::Cyan, false),
77+
anstyle::AnsiColor::White => (yansi::Color::White, false),
78+
anstyle::AnsiColor::BrightBlack => (yansi::Color::Black, true),
79+
anstyle::AnsiColor::BrightRed => (yansi::Color::Red, true),
80+
anstyle::AnsiColor::BrightGreen => (yansi::Color::Green, true),
81+
anstyle::AnsiColor::BrightYellow => (yansi::Color::Yellow, true),
82+
anstyle::AnsiColor::BrightBlue => (yansi::Color::Black, true),
83+
anstyle::AnsiColor::BrightMagenta => (yansi::Color::Magenta, true),
84+
anstyle::AnsiColor::BrightCyan => (yansi::Color::Cyan, true),
85+
anstyle::AnsiColor::BrightWhite => (yansi::Color::White, true),
8286
}
8387
}
8488

0 commit comments

Comments
 (0)