mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-08 00:44:30 +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")
|
.default_value("auto")
|
||||||
.help("When to use the pager"),
|
.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(
|
||||||
Arg::with_name("list-languages")
|
Arg::with_name("list-languages")
|
||||||
.long("list-languages")
|
.long("list-languages")
|
||||||
@ -135,7 +143,16 @@ impl App {
|
|||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
output_components: self.output_components()?,
|
output_components: self.output_components()?,
|
||||||
language: self.matches.value_of("language"),
|
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") {
|
colored_output: match self.matches.value_of("color") {
|
||||||
Some("always") => true,
|
Some("always") => true,
|
||||||
Some("never") => false,
|
Some("never") => false,
|
||||||
|
@ -94,7 +94,7 @@ impl<'a> Printer<'a> {
|
|||||||
regions: &[(highlighting::Style, &str)],
|
regions: &[(highlighting::Style, &str)],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut cursor: usize = 0;
|
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.
|
// Line decoration.
|
||||||
let decorations = self.gen_decorations(line_number);
|
let decorations = self.gen_decorations(line_number);
|
||||||
@ -116,6 +116,27 @@ impl<'a> Printer<'a> {
|
|||||||
// Grid border.
|
// Grid border.
|
||||||
let border = if gutter_width > 0 && self.config.output_components.grid() {
|
let border = if gutter_width > 0 && self.config.output_components.grid() {
|
||||||
self.gen_border()
|
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 {
|
} else {
|
||||||
for &(style, text) in regions.iter() {
|
for &(style, text) in regions.iter() {
|
||||||
let mut chars = text.chars().filter(|c| *c != '\n');
|
let mut chars = text.chars().filter(|c| *c != '\n');
|
||||||
@ -136,7 +157,7 @@ impl<'a> Printer<'a> {
|
|||||||
style,
|
style,
|
||||||
&*text,
|
&*text,
|
||||||
self.config.true_color,
|
self.config.true_color,
|
||||||
self.config.colored_output
|
self.config.colored_output,
|
||||||
)
|
)
|
||||||
)?;
|
)?;
|
||||||
break;
|
break;
|
||||||
@ -155,7 +176,7 @@ impl<'a> Printer<'a> {
|
|||||||
style,
|
style,
|
||||||
&*text,
|
&*text,
|
||||||
self.config.true_color,
|
self.config.true_color,
|
||||||
self.config.colored_output
|
self.config.colored_output,
|
||||||
),
|
),
|
||||||
" ".repeat(gutter_width),
|
" ".repeat(gutter_width),
|
||||||
border.text.to_owned()
|
border.text.to_owned()
|
||||||
|
@ -16,6 +16,7 @@ pub enum OutputComponent {
|
|||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||||
pub enum OutputWrap {
|
pub enum OutputWrap {
|
||||||
Character,
|
Character,
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputComponent {
|
impl OutputComponent {
|
||||||
|
Loading…
Reference in New Issue
Block a user