| •1 |
use ansi_termrust-analyzer cargo nu-ansi-term 0.50.3 crate/::Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::{selfrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#, Fixedrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Fixed#, Rgbrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Rgb#}; |
| 2 |
use ansi_termrust-analyzer cargo nu-ansi-term 0.50.3 crate/::{selfrust-analyzer cargo nu-ansi-term 0.50.3 crate/, Stylerust-analyzer cargo nu-ansi-term 0.50.3 style/Style#}; |
| 3 |
|
| 4 |
use syntectrust-analyzer cargo syntect 5.3.0 crate/::highlightingrust-analyzer cargo syntect 5.3.0 highlighting/::{selfrust-analyzer cargo syntect 5.3.0 highlighting/, FontStylerust-analyzer cargo syntect 5.3.0 highlighting/style/FontStyle#}; |
| 5 |
|
| 6 |
pub fn to_ansi_colorrust-analyzer cargo git-delta 0.19.2 utils/bat/terminal/to_ansi_color().(color: highlightingrust-analyzer cargo syntect 5.3.0 highlighting/::Colorrust-analyzer cargo syntect 5.3.0 highlighting/style/Color#, true_color: bool) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ansi_termrust-analyzer cargo nu-ansi-term 0.50.3 crate/::Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#> { |
| 7 |
if color.arust-analyzer cargo syntect 5.3.0 highlighting/style/Color#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 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, base16, |
| 11 |
// and base16-256 use this. |
| 12 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(match color.rrust-analyzer cargo syntect 5.3.0 highlighting/style/Color#r. { |
| 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. |
| 17 |
0x00 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Blackrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Black#, |
| 18 |
0x01 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Redrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Red#, |
| 19 |
0x02 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Greenrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Green#, |
| 20 |
0x03 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Yellowrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Yellow#, |
| 21 |
0x04 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Bluerust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Blue#, |
| 22 |
0x05 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Purplerust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Purple#, |
| 23 |
0x06 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Cyanrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Cyan#, |
| 24 |
0x07 => Colorrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#::Whiterust-analyzer cargo nu-ansi-term 0.50.3 style/Color#White#, |
| 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. |
| 29 |
// |
| 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. |
| 33 |
n => Fixedrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Fixed#(n), |
| 34 |
}) |
| 35 |
} else if color.arust-analyzer cargo syntect 5.3.0 highlighting/style/Color#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1 { |
| 36 |
// Themes can specify the terminal's default foreground/background color |
| 37 |
// (i.e. no escape sequence) using the encoding #RRGGBBAA with AA set to |
| 38 |
// 01. The built-in theme ansi uses this. |
| 39 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 40 |
} else if true_color { |
| •41 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Rgbrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Rgb#(color.rrust-analyzer cargo syntect 5.3.0 highlighting/style/Color#r., color.grust-analyzer cargo syntect 5.3.0 highlighting/style/Color#g., color.brust-analyzer cargo syntect 5.3.0 highlighting/style/Color#b.)) |
| 42 |
} else { |
| 43 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Fixedrust-analyzer cargo nu-ansi-term 0.50.3 style/Color#Fixed#(ansi_coloursrust-analyzer cargo ansi_colours 1.2.2 crate/::ansi256_from_rgbrust-analyzer cargo ansi_colours 1.2.2 ansi256_from_rgb().(( |
| 44 |
color.rrust-analyzer cargo syntect 5.3.0 highlighting/style/Color#r., color.grust-analyzer cargo syntect 5.3.0 highlighting/style/Color#g., color.brust-analyzer cargo syntect 5.3.0 highlighting/style/Color#b., |
| 45 |
)))) |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
#[allow(dead_code)] |
| 50 |
pub fn as_terminal_escapedrust-analyzer cargo git-delta 0.19.2 utils/bat/terminal/as_terminal_escaped().( |
| 51 |
style: highlightingrust-analyzer cargo syntect 5.3.0 highlighting/::Stylerust-analyzer cargo syntect 5.3.0 highlighting/style/Style#, |
| 52 |
text: &str, |
| 53 |
true_color: bool, |
| 54 |
colored: bool, |
| 55 |
italics: bool, |
| 56 |
background_color: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<highlightingrust-analyzer cargo syntect 5.3.0 highlighting/::Colorrust-analyzer cargo syntect 5.3.0 highlighting/style/Color#>, |
| 57 |
) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 58 |
if text.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 59 |
return text.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 60 |
} |
| 61 |
|
| 62 |
let mut style = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().colored { |
| 63 |
Stylerust-analyzer cargo nu-ansi-term 0.50.3 style/Style#::defaultrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style][Default]default().() |
| 64 |
} else { |
| 65 |
let mut color = Stylerust-analyzer cargo nu-ansi-term 0.50.3 style/Style# { |
| 66 |
foregroundrust-analyzer cargo nu-ansi-term 0.50.3 style/Style#foreground.: to_ansi_colorrust-analyzer cargo git-delta 0.19.2 utils/bat/terminal/to_ansi_color().(style.foregroundrust-analyzer cargo syntect 5.3.0 highlighting/style/Style#foreground., true_color), |
| 67 |
..Stylerust-analyzer cargo nu-ansi-term 0.50.3 style/Style#::defaultrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style][Default]default().() |
| 68 |
}; |
| 69 |
if style.font_stylerust-analyzer cargo syntect 5.3.0 highlighting/style/Style#font_style..containsrust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]contains().(FontStylerust-analyzer cargo syntect 5.3.0 highlighting/style/FontStyle#::BOLDrust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]BOLD.) { |
| 70 |
color = color.boldrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style]bold().(); |
| 71 |
} |
| 72 |
if style.font_stylerust-analyzer cargo syntect 5.3.0 highlighting/style/Style#font_style..containsrust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]contains().(FontStylerust-analyzer cargo syntect 5.3.0 highlighting/style/FontStyle#::UNDERLINErust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]UNDERLINE.) { |
| 73 |
color = color.underlinerust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style]underline().(); |
| 74 |
} |
| 75 |
if italics && style.font_stylerust-analyzer cargo syntect 5.3.0 highlighting/style/Style#font_style..containsrust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]contains().(FontStylerust-analyzer cargo syntect 5.3.0 highlighting/style/FontStyle#::ITALICrust-analyzer cargo syntect 5.3.0 highlighting/style/impl#[FontStyle]ITALIC.) { |
| 76 |
color = color.italicrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style]italic().(); |
| 77 |
} |
| 78 |
color |
| 79 |
}; |
| 80 |
|
| 81 |
style.backgroundrust-analyzer cargo nu-ansi-term 0.50.3 style/Style#background. = background_color.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|c| to_ansi_colorrust-analyzer cargo git-delta 0.19.2 utils/bat/terminal/to_ansi_color().(c, true_color)); |
| 82 |
style.paintrust-analyzer cargo nu-ansi-term 0.50.3 display/impl#[Style]paint().(text).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 83 |
} |