mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: disable ANSI escape sequences in ya pkg when stdout is not a TTY
This commit is contained in:
parent
798d38e494
commit
423dc8b344
3 changed files with 18 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -5528,6 +5528,7 @@ dependencies = [
|
|||
"yazi-fs",
|
||||
"yazi-macro",
|
||||
"yazi-shared",
|
||||
"yazi-term",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ yazi-dds = { path = "../yazi-dds", version = "26.1.4" }
|
|||
yazi-fs = { path = "../yazi-fs", version = "26.1.4" }
|
||||
yazi-macro = { path = "../yazi-macro", version = "26.1.4" }
|
||||
yazi-shared = { path = "../yazi-shared", version = "26.1.4" }
|
||||
yazi-term = { path = "../yazi-term", version = "26.1.4" }
|
||||
|
||||
# External dependencies
|
||||
anyhow = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -47,16 +47,29 @@ impl Dependency {
|
|||
|
||||
pub(super) fn header(&self, s: &str) -> Result<()> {
|
||||
use crossterm::style::{Attribute, Print, SetAttributes};
|
||||
use std::io::IsTerminal;
|
||||
use yazi_term::If;
|
||||
|
||||
fn styles_enabled() -> bool {
|
||||
if let Ok(v) = std::env::var("YA_FORCE_ANSI")
|
||||
&& !v.is_empty()
|
||||
&& v != "0"
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::io::stdout().is_terminal()
|
||||
}
|
||||
|
||||
let styled = styles_enabled();
|
||||
crossterm::execute!(
|
||||
BufWriter::new(std::io::stdout()),
|
||||
Print("\n"),
|
||||
SetAttributes(Attribute::Reverse.into()),
|
||||
SetAttributes(Attribute::Bold.into()),
|
||||
If(styled, SetAttributes(Attribute::Reverse.into())),
|
||||
If(styled, SetAttributes(Attribute::Bold.into())),
|
||||
Print(" "),
|
||||
Print(s.replacen("{name}", &self.name, 1)),
|
||||
Print(" "),
|
||||
SetAttributes(Attribute::Reset.into()),
|
||||
If(styled, SetAttributes(Attribute::Reset.into())),
|
||||
Print("\n\n"),
|
||||
)?;
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue