1use ansi_term::Colour::{Fixed, RGB};
3use syntect::highlighting::{self, FontStyle};
5/// Approximate a 24 bit color value by a 8 bit ANSI code
6fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
16 let fr = f32::from(r);
17 (((fr - 8.) / 247.) * 24.) as u8 + 232
20 let fr = f32::from(r);
21 let fg = f32::from(g);
22 let fb = f32::from(b);
23 16 + (36 * (fr / 255. * 5.) as u8) + (6 * (fg / 255. * 5.) as u8) + (fb / 255. * 5.) as u8
27pub fn as_terminal_escaped(
28 style: highlighting::Style,
33 let style = if !colored {
36 let color = if true_color {
37 RGB(style.foreground.r, style.foreground.g, style.foreground.b)
39 let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
43 if style.font_style.contains(FontStyle::BOLD) {
45 } else if style.font_style.contains(FontStyle::UNDERLINE) {
47 } else if style.font_style.contains(FontStyle::ITALIC) {
54 style.paint(text).to_string()
58fn test_rgb2ansi_black_white() {
59 assert_eq!(16, rgb2ansi(0x00, 0x00, 0x00));
60 assert_eq!(231, rgb2ansi(0xff, 0xff, 0xff));
64fn test_rgb2ansi_gray() {
65 assert_eq!(241, rgb2ansi(0x6c, 0x6c, 0x6c));
66 assert_eq!(233, rgb2ansi(0x1c, 0x1c, 0x1c));
70fn test_rgb2ansi_color() {
71 assert_eq!(96, rgb2ansi(0x87, 0x5f, 0x87));
72 assert_eq!(141, rgb2ansi(0xaf, 0x87, 0xff));
73 assert_eq!(193, rgb2ansi(0xd7, 0xff, 0xaf));
77fn test_rgb2ansi_approx() {
78 assert_eq!(231, rgb2ansi(0xfe, 0xfe, 0xfe));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list