mirror of
https://github.com/ilyakooo0/bat.git
synced 2024-11-13 06:01:02 +03:00
Merge branch 'master' into master
This commit is contained in:
commit
bdd10b8bec
@ -2,7 +2,7 @@ use std::fmt::Write;
|
|||||||
|
|
||||||
use ansi_term::Colour::{Fixed, RGB};
|
use ansi_term::Colour::{Fixed, RGB};
|
||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
use syntect::highlighting;
|
use syntect::highlighting::{self, FontStyle};
|
||||||
|
|
||||||
/// Approximate a 24 bit color value by a 8 bit ANSI code
|
/// Approximate a 24 bit color value by a 8 bit ANSI code
|
||||||
fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
|
fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
|
||||||
@ -27,18 +27,31 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_terminal_escaped(
|
pub fn as_terminal_escaped(
|
||||||
color: highlighting::Style,
|
style: highlighting::Style,
|
||||||
text: &str,
|
text: &str,
|
||||||
true_color: bool,
|
true_color: bool,
|
||||||
colored: bool,
|
colored: bool,
|
||||||
) -> String {
|
) -> String {
|
||||||
|
|
||||||
let style = if !colored {
|
let style = if !colored {
|
||||||
Style::default()
|
Style::default()
|
||||||
} else if true_color {
|
|
||||||
RGB(color.foreground.r, color.foreground.g, color.foreground.b).normal()
|
|
||||||
} else {
|
} else {
|
||||||
let ansi = rgb2ansi(color.foreground.r, color.foreground.g, color.foreground.b);
|
let color = if true_color {
|
||||||
Fixed(ansi).normal()
|
RGB(style.foreground.r, style.foreground.g, style.foreground.b)
|
||||||
|
} else {
|
||||||
|
let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
|
||||||
|
Fixed(ansi)
|
||||||
|
};
|
||||||
|
|
||||||
|
if style.font_style.contains(FontStyle::BOLD) {
|
||||||
|
color.bold()
|
||||||
|
} else if style.font_style.contains(FontStyle::UNDERLINE) {
|
||||||
|
color.underline()
|
||||||
|
} else if style.font_style.contains(FontStyle::ITALIC) {
|
||||||
|
color.italic()
|
||||||
|
} else {
|
||||||
|
color.normal()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut s: String = String::new();
|
let mut s: String = String::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user