Repository: sxyazi/yazi
File: yazi-cli/src/package/dependency.rs (Rust)

Code before:
		// Support more Git hosting services in the future
		format!("https://github.com/{}.git", self.parent)
	}

	pub(super) fn target(&self) -> PathBuf {
		if self.is_flavor {
			Xdg::config_dir().join(format!("flavors/{}", self.name))
		} else {
			Xdg::config_dir().join(format!("plugins/{}", self.name))
		}
	}

	pub(super) fn identical(&self, other: &Self) -> bool {
		self.parent == other.parent && self.child == other.child
	}

	pub(super) fn header(&self, s: &str) -> Result<()> {
		let text = s.replacen("{name}", &self.name, 1);

		if yazi_shared::styles_enabled() {
			use crossterm::style::{Attribute, Print, SetAttributes};

			crossterm::execute!(
				BufWriter::new(std::io::stdout()),
				Print("\n"),
				SetAttributes(Attribute::Reverse.into()),
				SetAttributes(Attribute::Bold.into()),
				Print("  "),
				Print(&text),
				Print("  "),
				SetAttributes(Attribute::Reset.into()),
				Print("\n\n"),
			)?;
		} else {
			use std::io::Write;
			writeln!(BufWriter::new(std::io::stdout()), "\n  {text}  \n")?;
		}
		Ok(())
	}

	pub(super) async fn plugin_files(dir: &Path) -> std::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();
		while let Some(entry) = it.next_entry().await? {
			if let Ok(name) = entry.file_name().into_string()
				&& let Some(stripped) = name.strip_suffix(".lua")
				&& stripped != "main"
				&& stripped.as_bytes().kebab_cased()
			{
				files.push(name);

Review comment (refactor):
Please simplify the code with [`If`](https://github.com/sxyazi/yazi/blob/0c8c973e6c766ff026665e487a33ad82f0c7e4f8/yazi-term/src/if.rs#L1)


```suggestion
				If(is_tty, SetAttributes(Attribute::Reverse.into())),
```

Code after:
		// Support more Git hosting services in the future
		format!("https://github.com/{}.git", self.parent)
	}

	pub(super) fn target(&self) -> PathBuf {
		if self.is_flavor {
			Xdg::config_dir().join(format!("flavors/{}", self.name))
		} else {
			Xdg::config_dir().join(format!("plugins/{}", self.name))
		}
	}

	pub(super) fn identical(&self, other: &Self) -> bool {
		self.parent == other.parent && self.child == other.child
	}

	pub(super) fn header(&self, s: &str) -> Result<()> {
		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(io::stdout()),
			Print("\n"),
			If(ansi, SetAttributes(Attribute::Reverse.into())),
			If(ansi, SetAttributes(Attribute::Bold.into())),
			Print("  "),
			Print(s.replacen("{name}", &self.name, 1)),
			Print("  "),
			If(ansi, SetAttributes(Attribute::Reset.into())),
			Print("\n\n"),
		)?;
		Ok(())
	}

	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();
		while let Some(entry) = it.next_entry().await? {
			if let Ok(name) = entry.file_name().into_string()
				&& let Some(stripped) = name.strip_suffix(".lua")
				&& stripped != "main"
				&& stripped.as_bytes().kebab_cased()
			{
				files.push(name);
			}
		}
		files.sort_unstable();