mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
423dc8b344
commit
de43089257
1 changed files with 9 additions and 18 deletions
|
|
@ -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 anyhow::{Result, bail};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
@ -46,36 +46,27 @@ impl Dependency {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn header(&self, s: &str) -> Result<()> {
|
pub(super) fn header(&self, s: &str) -> Result<()> {
|
||||||
use crossterm::style::{Attribute, Print, SetAttributes};
|
|
||||||
use std::io::IsTerminal;
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
|
use crossterm::style::{Attribute, Print, SetAttributes};
|
||||||
use yazi_term::If;
|
use yazi_term::If;
|
||||||
|
|
||||||
fn styles_enabled() -> bool {
|
let ansi = env::var_os("YA_FORCE_ANSI").is_some_and(|v| v == "1") || io::stdout().is_terminal();
|
||||||
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!(
|
crossterm::execute!(
|
||||||
BufWriter::new(std::io::stdout()),
|
BufWriter::new(io::stdout()),
|
||||||
Print("\n"),
|
Print("\n"),
|
||||||
If(styled, SetAttributes(Attribute::Reverse.into())),
|
If(ansi, SetAttributes(Attribute::Reverse.into())),
|
||||||
If(styled, SetAttributes(Attribute::Bold.into())),
|
If(ansi, SetAttributes(Attribute::Bold.into())),
|
||||||
Print(" "),
|
Print(" "),
|
||||||
Print(s.replacen("{name}", &self.name, 1)),
|
Print(s.replacen("{name}", &self.name, 1)),
|
||||||
Print(" "),
|
Print(" "),
|
||||||
If(styled, SetAttributes(Attribute::Reset.into())),
|
If(ansi, SetAttributes(Attribute::Reset.into())),
|
||||||
Print("\n\n"),
|
Print("\n\n"),
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
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 it = ok_or_not_found!(tokio::fs::read_dir(dir).await, return Ok(vec![]));
|
||||||
let mut files: Vec<String> =
|
let mut files: Vec<String> =
|
||||||
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
|
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue