mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-07 16:34:13 +01:00
Fix padding, add --wrap argument, disable wrap for non-tty. (Fixed)
I'm not quite sure what was up with git on that last commit, but it's all properly committed now.
This commit is contained in:
parent
cd26d403a3
commit
d4b438b9d3
19
src/app.rs
19
src/app.rs
@ -80,6 +80,14 @@ impl App {
|
||||
.default_value("auto")
|
||||
.help("When to use the pager"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("wrap")
|
||||
.long("wrap")
|
||||
.takes_value(true)
|
||||
.possible_values(&["character", "never"])
|
||||
.default_value("character")
|
||||
.help("When to wrap text"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("list-languages")
|
||||
.long("list-languages")
|
||||
@ -135,7 +143,16 @@ impl App {
|
||||
true_color: is_truecolor_terminal(),
|
||||
output_components: self.output_components()?,
|
||||
language: self.matches.value_of("language"),
|
||||
output_wrap: OutputWrap::Character,
|
||||
output_wrap: if ! self.interactive_output {
|
||||
// We don't have the tty width when piping to another program.
|
||||
// There's no point in wrapping when this is the case.
|
||||
OutputWrap::None
|
||||
} else {
|
||||
match self.matches.value_of("wrap") {
|
||||
Some("character") => OutputWrap::Character,
|
||||
Some("never") | _ => OutputWrap::None,
|
||||
}
|
||||
},
|
||||
colored_output: match self.matches.value_of("color") {
|
||||
Some("always") => true,
|
||||
Some("never") => false,
|
||||
|
@ -94,7 +94,7 @@ impl<'a> Printer<'a> {
|
||||
regions: &[(highlighting::Style, &str)],
|
||||
) -> Result<()> {
|
||||
let mut cursor: usize = 0;
|
||||
let mut cursor_max: usize = self.config.term_width - 2;
|
||||
let mut cursor_max: usize = self.config.term_width;
|
||||
|
||||
// Line decoration.
|
||||
let decorations = self.gen_decorations(line_number);
|
||||
@ -116,6 +116,27 @@ impl<'a> Printer<'a> {
|
||||
// Grid border.
|
||||
let border = if gutter_width > 0 && self.config.output_components.grid() {
|
||||
self.gen_border()
|
||||
} else {
|
||||
PrintSegment {
|
||||
size: 0,
|
||||
text: "".to_owned(),
|
||||
}
|
||||
};
|
||||
|
||||
cursor_max -= border.size;
|
||||
write!(self.handle, "{}", border.text)?;
|
||||
|
||||
// Line contents.
|
||||
if self.config.output_wrap == OutputWrap::None {
|
||||
let true_color = self.config.true_color;
|
||||
let colored_output = self.config.colored_output;
|
||||
|
||||
write!(self.handle, "{}",
|
||||
regions.iter()
|
||||
.map(|&(style, text)| as_terminal_escaped(style, text, true_color, colored_output))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
)?;
|
||||
} else {
|
||||
for &(style, text) in regions.iter() {
|
||||
let mut chars = text.chars().filter(|c| *c != '\n');
|
||||
@ -136,7 +157,7 @@ impl<'a> Printer<'a> {
|
||||
style,
|
||||
&*text,
|
||||
self.config.true_color,
|
||||
self.config.colored_output
|
||||
self.config.colored_output,
|
||||
)
|
||||
)?;
|
||||
break;
|
||||
@ -155,7 +176,7 @@ impl<'a> Printer<'a> {
|
||||
style,
|
||||
&*text,
|
||||
self.config.true_color,
|
||||
self.config.colored_output
|
||||
self.config.colored_output,
|
||||
),
|
||||
" ".repeat(gutter_width),
|
||||
border.text.to_owned()
|
||||
|
@ -16,6 +16,7 @@ pub enum OutputComponent {
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||
pub enum OutputWrap {
|
||||
Character,
|
||||
None
|
||||
}
|
||||
|
||||
impl OutputComponent {
|
||||
|
Loading…
Reference in New Issue
Block a user