Skip to content

Commit 0644548

Browse files
Henry Limmgierens
Henry Limm
authored andcommitted
Add "bright" builtin codes and tests.
1 parent 5023a43 commit 0644548

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/ansi.rs

+19
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ impl Colour {
9898
Colour::Purple => write!(f, "35"),
9999
Colour::Cyan => write!(f, "36"),
100100
Colour::White => write!(f, "37"),
101+
102+
Colour::BrightBlack => write!(f, "90"),
103+
Colour::BrightRed => write!(f, "91"),
104+
Colour::BrightGreen => write!(f, "92"),
105+
Colour::BrightYellow => write!(f, "93"),
106+
Colour::BrightBlue => write!(f, "94"),
107+
Colour::BrightPurple => write!(f, "95"),
108+
Colour::BrightCyan => write!(f, "96"),
109+
Colour::BrightWhite => write!(f, "97"),
101110
Colour::Fixed(num) => write!(f, "38;5;{}", &num),
102111
Colour::RGB(r,g,b) => write!(f, "38;2;{};{};{}", &r, &g, &b),
103112
}
@@ -113,6 +122,14 @@ impl Colour {
113122
Colour::Purple => write!(f, "45"),
114123
Colour::Cyan => write!(f, "46"),
115124
Colour::White => write!(f, "47"),
125+
Colour::BrightBlack => write!(f, "100"),
126+
Colour::BrightRed => write!(f, "101"),
127+
Colour::BrightGreen => write!(f, "102"),
128+
Colour::BrightYellow => write!(f, "103"),
129+
Colour::BrightBlue => write!(f, "104"),
130+
Colour::BrightPurple => write!(f, "105"),
131+
Colour::BrightCyan => write!(f, "106"),
132+
Colour::BrightWhite => write!(f, "107"),
116133
Colour::Fixed(num) => write!(f, "48;5;{}", &num),
117134
Colour::RGB(r,g,b) => write!(f, "48;2;{};{};{}", &r, &g, &b),
118135
}
@@ -456,6 +473,8 @@ mod test {
456473
test!(hyperlink_plain: Style::new().hyperlink("url"); "hi" => "\x1B[m\x1B]8;;url\x1B\\hi\x1B]8;;\x1B\\\x1B[0m");
457474
test!(hyperlink_color: Blue.hyperlink("url"); "hi" => "\x1B[34m\x1B]8;;url\x1B\\hi\x1B]8;;\x1B\\\x1B[0m");
458475
test!(hyperlink_style: Blue.underline().hyperlink("url"); "hi" => "\x1B[4;34m\x1B]8;;url\x1B\\hi\x1B]8;;\x1B\\\x1B[0m");
476+
test!(brightgreen: BrightGreen; "hi" => "\x1B[92mhi\x1B[0m");
477+
test!(brightred_on_brightblue: BrightRed.on(BrightBlue); "hi" => "\x1B[104;91mhi\x1B[0m");
459478

460479
#[test]
461480
fn test_infix() {

src/style.rs

+30
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,36 @@ pub enum Colour {
305305
/// hard to read on terminals with light backgrounds.
306306
White,
307307

308+
/// Colour #8 (foreground code `30`, background code `40`).
309+
///
310+
/// This is not necessarily the background colour, and using it as one may
311+
/// render the text hard to read on terminals with dark backgrounds.
312+
BrightBlack,
313+
314+
/// Colour #9 (foreground code `91`, background code `101`).
315+
BrightRed,
316+
317+
/// Colour #10 (foreground code `92`, background code `102`).
318+
BrightGreen,
319+
320+
/// Colour #11 (foreground code `93`, background code `103`).
321+
BrightYellow,
322+
323+
/// Colour #12 (foreground code `94`, background code `104`).
324+
BrightBlue,
325+
326+
/// Colour #13 (foreground code `95`, background code `105`).
327+
BrightPurple,
328+
329+
/// Colour #14 (foreground code `96`, background code `106`).
330+
BrightCyan,
331+
332+
/// Colour #15 (foreground code `97`, background code `107`).
333+
///
334+
/// As above, this is not necessarily the foreground colour, and may be
335+
/// hard to read on terminals with light backgrounds.
336+
BrightWhite,
337+
308338
/// A colour number from 0 to 255, for use in 256-colour terminal
309339
/// environments.
310340
///

0 commit comments

Comments
 (0)