1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-10-03 18:42:28 +01:00

Added line wrapping.

This commit is contained in:
eth-p
2018-05-11 21:59:26 -07:00
parent 22c8978fca
commit 4e4110bf50
4 changed files with 214 additions and 85 deletions

View File

@@ -26,26 +26,46 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
}
}
//pub fn as_terminal_escaped(
// v: &[(highlighting::Style, &str)],
// true_color: bool,
// colored: bool,
//) -> String {
// let mut s: String = String::new();
// for &(ref style, text) in v.iter() {
// let style = if !colored {
// Style::default()
// } else if true_color {
// RGB(style.foreground.r, style.foreground.g, style.foreground.b).normal()
// } else {
// let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
// Fixed(ansi).normal()
// };
//
// write!(s, "{}", style.paint(text)).unwrap();
// }
//
// s
//}
pub fn as_terminal_escaped(
v: &[(highlighting::Style, &str)],
color:highlighting::Style,
text: &str,
true_color: bool,
colored: bool,
) -> String {
let style = if !colored {
Style::default()
} else if true_color {
RGB(color.foreground.r, color.foreground.g, color.foreground.b).normal()
} else {
let ansi = rgb2ansi(color.foreground.r, color.foreground.g, color.foreground.b);
Fixed(ansi).normal()
};
let mut s: String = String::new();
for &(ref style, text) in v.iter() {
let style = if !colored {
Style::default()
} else if true_color {
RGB(style.foreground.r, style.foreground.g, style.foreground.b).normal()
} else {
let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
Fixed(ansi).normal()
};
write!(s, "{}", style.paint(text)).unwrap();
}
s
write!(s, "{}", style.paint(text)).unwrap();
return s;
}
#[test]