Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30091a5

Browse files
Implement pipe handling
Ref: rust-lang/rust#46016 (comment) Fixes: clearloop#21
1 parent 0d68c73 commit 30091a5

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

‎Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ features = ["precommit-hook", "user-hooks"]
4848

4949
[features]
5050
pym = ["pyo3"]
51+
52+
[target.'cfg(target_family = "unix")'.dependencies]
53+
nix = "0.17.0"

‎src/cli.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,24 @@ use crate::{
99
};
1010
use clap::{crate_name, crate_version, App, AppSettings};
1111

12+
/// This should be called before calling any cli method or printing any output.
13+
pub fn reset_signal_pipe_handler() -> Result<(), ()> {
14+
#[cfg(target_family = "unix")]
15+
{
16+
use nix::sys::signal;
17+
18+
unsafe {
19+
signal::signal(signal::Signal::SIGPIPE, signal::SigHandler::SigDfl)
20+
.map_err(|e| println!("{:?}", e))?;
21+
}
22+
}
23+
24+
Ok(())
25+
}
26+
1227
/// Get maches
1328
pub async fn main() -> Result<(), Error> {
29+
let _ = reset_signal_pipe_handler();
1430
let m = App::new(crate_name!())
1531
.version(crate_version!())
1632
.about("May the Code be with You 👻")

‎src/cmds/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use super::Command;
3737
use crate::{cache::Cache, err::Error, helper::Digit};
3838
use async_trait::async_trait;
3939
use clap::{App, Arg, ArgMatches, SubCommand};
40+
use std::io::{self, Write};
4041
/// Abstract `list` command
4142
///
4243
/// ## handler
@@ -168,9 +169,8 @@ impl Command for ListCommand {
168169
ps.retain(|x| x.name.contains(&keyword));
169170
}
170171

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

175175
// one more thing, filter stat
176176
if m.is_present("stat") {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /