mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
feat: disable ANSI escape sequences in ya pkg when stdout is not a TTY (#3566)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
798d38e494
commit
8a909697f8
4 changed files with 15 additions and 7 deletions
|
|
@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
- Tree view for the preset archive previewer ([#3525])
|
||||
- Support compressed tarballs (`.tar.gz`, `.tar.bz2`, etc.) in the preset archive previewer ([#3518])
|
||||
- Check and refresh the file list when the terminal gains focus ([#3561])
|
||||
- Disable ANSI escape sequences in `ya pkg` when stdout is not a TTY ([#3566])
|
||||
- New `Path.os()` API creates an OS-native `Path` ([#3541])
|
||||
|
||||
### Fixed
|
||||
|
|
@ -1603,3 +1604,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
[#3540]: https://github.com/sxyazi/yazi/pull/3540
|
||||
[#3541]: https://github.com/sxyazi/yazi/pull/3541
|
||||
[#3561]: https://github.com/sxyazi/yazi/pull/3561
|
||||
[#3566]: https://github.com/sxyazi/yazi/pull/3566
|
||||
|
|
|
|||
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 }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{io::BufWriter, path::{Path, PathBuf}, str::FromStr};
|
||||
use std::{env, io::{self, BufWriter}, path::{Path, PathBuf}, str::FromStr};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
|
@ -46,23 +46,27 @@ impl Dependency {
|
|||
}
|
||||
|
||||
pub(super) fn header(&self, s: &str) -> Result<()> {
|
||||
use crossterm::style::{Attribute, Print, SetAttributes};
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use crossterm::style::{Attribute, Print, SetAttributes};
|
||||
use yazi_term::If;
|
||||
|
||||
let ansi = env::var_os("YA_FORCE_ANSI").is_some_and(|v| v == "1") || io::stdout().is_terminal();
|
||||
crossterm::execute!(
|
||||
BufWriter::new(std::io::stdout()),
|
||||
BufWriter::new(io::stdout()),
|
||||
Print("\n"),
|
||||
SetAttributes(Attribute::Reverse.into()),
|
||||
SetAttributes(Attribute::Bold.into()),
|
||||
If(ansi, SetAttributes(Attribute::Reverse.into())),
|
||||
If(ansi, SetAttributes(Attribute::Bold.into())),
|
||||
Print(" "),
|
||||
Print(s.replacen("{name}", &self.name, 1)),
|
||||
Print(" "),
|
||||
SetAttributes(Attribute::Reset.into()),
|
||||
If(ansi, SetAttributes(Attribute::Reset.into())),
|
||||
Print("\n\n"),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn plugin_files(dir: &Path) -> std::io::Result<Vec<String>> {
|
||||
pub(super) async fn plugin_files(dir: &Path) -> io::Result<Vec<String>> {
|
||||
let mut it = ok_or_not_found!(tokio::fs::read_dir(dir).await, return Ok(vec![]));
|
||||
let mut files: Vec<String> =
|
||||
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue