diff --git a/cspell.json b/cspell.json index 9e3f47328..f1cbd0af0 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase"],"version":"0.2","language":"en"} \ No newline at end of file +{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase","outln","errln","tmtheme"],"version":"0.2","language":"en"} \ No newline at end of file diff --git a/yazi-cli/src/main.rs b/yazi-cli/src/main.rs index 1be1827fa..26e46c4b5 100644 --- a/yazi-cli/src/main.rs +++ b/yazi-cli/src/main.rs @@ -2,20 +2,40 @@ yazi_macro::mod_pub!(package); yazi_macro::mod_flat!(args); +use std::process::ExitCode; + use clap::Parser; +use yazi_macro::{errln, outln}; #[tokio::main] -async fn main() -> anyhow::Result<()> { +async fn main() -> ExitCode { + match run().await { + Ok(()) => ExitCode::SUCCESS, + Err(e) => { + for cause in e.chain() { + if let Some(ioerr) = cause.downcast_ref::() { + if ioerr.kind() == std::io::ErrorKind::BrokenPipe { + return ExitCode::from(0); + } + } + } + errln!("{:#}", e).ok(); + ExitCode::FAILURE + } + } +} + +async fn run() -> anyhow::Result<()> { yazi_shared::init(); yazi_fs::init(); if std::env::args_os().nth(1).is_some_and(|s| s == "-V" || s == "--version") { - println!( + outln!( "Ya {} ({} {})", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA"), env!("VERGEN_BUILD_DATE") - ); + )?; return Ok(()); } @@ -26,7 +46,7 @@ async fn main() -> anyhow::Result<()> { if let Err(e) = yazi_dds::Client::shot("dds-emit", CommandPub::receiver()?, &cmd.body()?).await { - eprintln!("Cannot emit command: {e}"); + errln!("Cannot emit command: {e}")?; std::process::exit(1); } } @@ -35,7 +55,7 @@ async fn main() -> anyhow::Result<()> { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await { - eprintln!("Cannot emit command: {e}"); + errln!("Cannot emit command: {e}")?; std::process::exit(1); } } @@ -61,7 +81,7 @@ async fn main() -> anyhow::Result<()> { yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await { - eprintln!("Cannot send message: {e}"); + errln!("Cannot send message: {e}")?; std::process::exit(1); } } @@ -70,7 +90,7 @@ async fn main() -> anyhow::Result<()> { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await { - eprintln!("Cannot send message: {e}"); + errln!("Cannot send message: {e}")?; std::process::exit(1); } } diff --git a/yazi-cli/src/package/deploy.rs b/yazi-cli/src/package/deploy.rs index 36c6c6024..eb0f4119e 100644 --- a/yazi-cli/src/package/deploy.rs +++ b/yazi-cli/src/package/deploy.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use anyhow::{Context, Result, bail}; use tokio::fs; use yazi_fs::{Xdg, maybe_exists, must_exists, remove_dir_clean}; +use yazi_macro::outln; use super::Package; @@ -48,7 +49,7 @@ For safety, please manually delete it from your plugin/flavor directory and re-r Self::deploy_assets(from.join("assets"), to.join("assets")).await?; - println!("Done!"); + outln!("Done!")?; Ok(()) } diff --git a/yazi-cli/src/package/parser.rs b/yazi-cli/src/package/parser.rs index c034fa414..3a1b2c7ba 100644 --- a/yazi-cli/src/package/parser.rs +++ b/yazi-cli/src/package/parser.rs @@ -2,6 +2,7 @@ use anyhow::{Context, Result, bail}; use tokio::fs; use toml_edit::{Array, DocumentMut, InlineTable, Item, Value}; use yazi_fs::Xdg; +use yazi_macro::outln; use super::Package; @@ -78,13 +79,13 @@ impl Package { }; let deps = deps.as_array().context("`deps` must be an array")?; - println!("{section}s:"); + outln!("{section}s:")?; for dep in deps { let Some(dep) = dep.as_inline_table() else { continue }; match (dep.get("use").and_then(Value::as_str), dep.get("rev").and_then(Value::as_str)) { - (Some(use_), None) => println!("\t{use_}"), - (Some(use_), Some(rev)) => println!("\t{use_} ({rev})"), + (Some(use_), None) => outln!("\t{use_}")?, + (Some(use_), Some(rev)) => outln!("\t{use_} ({rev})")?, _ => {} } } diff --git a/yazi-macro/src/lib.rs b/yazi-macro/src/lib.rs index 858310db9..624c20f72 100644 --- a/yazi-macro/src/lib.rs +++ b/yazi-macro/src/lib.rs @@ -2,3 +2,4 @@ mod asset; mod event; mod module; mod platform; +mod stdio; diff --git a/yazi-macro/src/stdio.rs b/yazi-macro/src/stdio.rs new file mode 100644 index 000000000..fa80935b6 --- /dev/null +++ b/yazi-macro/src/stdio.rs @@ -0,0 +1,15 @@ +#[macro_export] +macro_rules! outln { + ($($tt:tt)*) => {{ + use std::io::Write; + writeln!(std::io::stdout(), $($tt)*) + }} +} + +#[macro_export] +macro_rules! errln { + ($($tt:tt)*) => {{ + use std::io::Write; + writeln!(std::io::stderr(), $($tt)*) + }} +}