1use ansi_term::Color::{self, Fixed, RGB};
2use ansi_term::{self, Style};
4use syntect::highlighting::{self, FontStyle};
6pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Color {
8 // Themes can specify one of the user-configurable terminal colors by
9 // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set
10 // to the 8-bit color palette number. The built-in themes ansi-light,
11 // ansi-dark, and base16 use this.
13 // For the first 8 colors, use the Color enum to produce ANSI escape
14 // sequences using codes 30-37 (foreground) and 40-47 (background).
15 // For example, red foreground is \x1b[31m. This works on terminals
16 // without 256-color support.
20 0x03 => Color::Yellow,
22 0x05 => Color::Purple,
25 // For all other colors, use Fixed to produce escape sequences using
26 // codes 38;5 (foreground) and 48;5 (background). For example,
27 // bright red foreground is \x1b[38;5;9m. This only works on
28 // terminals with 256-color support.
30 // TODO: When ansi_term adds support for bright variants using codes
31 // 90-97 (foreground) and 100-107 (background), we should use those
32 // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
35 } else if true_color {
36 RGB(color.r, color.g, color.b)
38 Fixed(ansi_colours::ansi256_from_rgb((color.r, color.g, color.b)))
42pub fn as_terminal_escaped(
43 style: highlighting::Style,
48 background_color: Option<highlighting::Color>,
51 return text.to_string();
54 let mut style = if !colored {
57 let mut color = Style::from(to_ansi_color(style.foreground, true_color));
58 if style.font_style.contains(FontStyle::BOLD) {
61 if style.font_style.contains(FontStyle::UNDERLINE) {
62 color = color.underline();
64 if italics && style.font_style.contains(FontStyle::ITALIC) {
65 color = color.italic();
70 style.background = background_color.map(|c| to_ansi_color(c, true_color));
71 style.paint(text).to_string()
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