mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-27 07:02:09 +01:00
Add check for non-terminal/tty handle
This commit is contained in:
parent
5727ccb928
commit
1eec98b070
@ -1,5 +1,6 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
use nu_ansi_term::Color::{Fixed, Green, Red, Yellow};
|
use nu_ansi_term::Color::{Fixed, Green, Red, Yellow};
|
||||||
@ -164,7 +165,8 @@ impl<'a> Printer for SimplePrinter<'a> {
|
|||||||
} else {
|
} else {
|
||||||
match handle {
|
match handle {
|
||||||
OutputHandle::IoWrite(handle) => {
|
OutputHandle::IoWrite(handle) => {
|
||||||
if self.config.style_components.numbers() {
|
if self.config.style_components.numbers() && !std::io::stdout().is_terminal()
|
||||||
|
{
|
||||||
handle.write_all(
|
handle.write_all(
|
||||||
format!("{line_number:4} {}", String::from_utf8_lossy(line_buffer))
|
format!("{line_number:4} {}", String::from_utf8_lossy(line_buffer))
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
|
@ -1779,7 +1779,7 @@ fn file_with_invalid_utf8_filename() {
|
|||||||
.arg(file_path.as_os_str())
|
.arg(file_path.as_os_str())
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(" 1 dummy content\n");
|
.stdout("dummy content\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user