Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ features = ["precommit-hook", "user-hooks"]

[features]
pym = ["pyo3"]

[target.'cfg(target_family = "unix")'.dependencies]
nix = "0.17.0"
16 changes: 16 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@ use crate::{
};
use clap::{crate_name, crate_version, App, AppSettings};

/// This should be called before calling any cli method or printing any output.
pub fn reset_signal_pipe_handler() -> Result<(), ()> {
#[cfg(target_family = "unix")]
{
use nix::sys::signal;

unsafe {
signal::signal(signal::Signal::SIGPIPE, signal::SigHandler::SigDfl)
.map_err(|e| println!("{:?}", e))?;
}
}

Ok(())
}

/// Get maches
pub async fn main() -> Result<(), Error> {
let _ = reset_signal_pipe_handler();
let m = App::new(crate_name!())
.version(crate_version!())
.about("May the Code be with You 👻")
Expand Down
6 changes: 3 additions & 3 deletions src/cmds/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use super::Command;
use crate::{cache::Cache, err::Error, helper::Digit};
use async_trait::async_trait;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::io::{self, Write};
/// Abstract `list` command
///
/// ## handler
Expand Down Expand Up @@ -168,9 +169,8 @@ impl Command for ListCommand {
ps.retain(|x| x.name.contains(&keyword));
}

for p in &ps {
println!("{}", p);
}
let out: Vec<String> = ps.iter().map(ToString::to_string).collect();
io::stdout().write_all(out.join("\n").as_bytes())?;

// one more thing, filter stat
if m.is_present("stat") {
Expand Down