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:
@@ -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]
|
||||
|
Reference in New Issue
Block a user