diff --git a/Cargo.lock b/Cargo.lock index 631a1df..c688981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,6 +229,7 @@ name = "xcolor" version = "0.5.1" dependencies = [ "anyhow", + "atty", "clap", "lazy_static", "nix", diff --git a/Cargo.toml b/Cargo.toml index d01fbdb..e7f1064 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ edition = "2018" [dependencies] anyhow = "1" +atty = "0.2" nom = "7" clap = "2" nix = "0.22" diff --git a/src/main.rs b/src/main.rs index 9d2ac51..d498e57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod selection; mod util; use anyhow::{anyhow, Result}; +use atty::Stream; use clap::{value_t, ArgMatches, ErrorKind}; use nix::unistd::ForkResult; use xcb::base::Connection; @@ -86,7 +87,8 @@ fn run(args: &ArgMatches) -> Result<()> { set_selection(&conn, root, &selection.unwrap(), &output)?; } } else { - println!("{}", output); + let trailing_newline = atty::is(Stream::Stdout).then_some("\n").unwrap_or(""); + print!("{}{}", output, trailing_newline); } } }