mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-19 04:21:06 +00:00
Add check for terminal-width in output_wrap config value in not interactive case
Co-authored-by: allevo <tomallevi@gmail.com> Co-authored-by: gildo <gildo.fiorito@gmail.com>
This commit is contained in:
parent
41d547532f
commit
6311ca22f9
@ -119,6 +119,24 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let maybe_term_width = self.matches.value_of("terminal-width").and_then(|w| {
|
||||||
|
if w.starts_with('+') || w.starts_with('-') {
|
||||||
|
// Treat argument as a delta to the current terminal width
|
||||||
|
w.parse().ok().map(|delta: i16| {
|
||||||
|
let old_width: u16 = Term::stdout().size().1;
|
||||||
|
let new_width: i32 = i32::from(old_width) + i32::from(delta);
|
||||||
|
|
||||||
|
if new_width <= 0 {
|
||||||
|
old_width as usize
|
||||||
|
} else {
|
||||||
|
new_width as usize
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
w.parse().ok()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
language: self.matches.value_of("language").or_else(|| {
|
language: self.matches.value_of("language").or_else(|| {
|
||||||
@ -129,11 +147,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
show_nonprintable: self.matches.is_present("show-all"),
|
show_nonprintable: self.matches.is_present("show-all"),
|
||||||
output_wrap: if !self.interactive_output {
|
output_wrap: if self.interactive_output || maybe_term_width.is_some() {
|
||||||
// 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") {
|
match self.matches.value_of("wrap") {
|
||||||
Some("character") => OutputWrap::Character,
|
Some("character") => OutputWrap::Character,
|
||||||
Some("never") => OutputWrap::None,
|
Some("never") => OutputWrap::None,
|
||||||
@ -145,6 +159,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 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
|
||||||
},
|
},
|
||||||
colored_output: match self.matches.value_of("color") {
|
colored_output: match self.matches.value_of("color") {
|
||||||
Some("always") => true,
|
Some("always") => true,
|
||||||
@ -152,27 +170,7 @@ impl App {
|
|||||||
Some("auto") | _ => self.interactive_output,
|
Some("auto") | _ => self.interactive_output,
|
||||||
},
|
},
|
||||||
paging_mode,
|
paging_mode,
|
||||||
term_width: self
|
term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize),
|
||||||
.matches
|
|
||||||
.value_of("terminal-width")
|
|
||||||
.and_then(|w| {
|
|
||||||
if w.starts_with('+') || w.starts_with('-') {
|
|
||||||
// Treat argument as a delta to the current terminal width
|
|
||||||
w.parse().ok().map(|delta: i16| {
|
|
||||||
let old_width: u16 = Term::stdout().size().1;
|
|
||||||
let new_width: i32 = i32::from(old_width) + i32::from(delta);
|
|
||||||
|
|
||||||
if new_width <= 0 {
|
|
||||||
old_width as usize
|
|
||||||
} else {
|
|
||||||
new_width as usize
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
w.parse().ok()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or(Term::stdout().size().1 as usize),
|
|
||||||
loop_through: !(self.interactive_output
|
loop_through: !(self.interactive_output
|
||||||
|| self.matches.value_of("color") == Some("always")
|
|| self.matches.value_of("color") == Some("always")
|
||||||
|| self.matches.value_of("decorations") == Some("always")),
|
|| self.matches.value_of("decorations") == Some("always")),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user