Skip to content

Commit

Permalink
std buffer manipulations (#10)
Browse files Browse the repository at this point in the history
* rebased

* fixed stdin
  • Loading branch information
bahdotsh authored Apr 13, 2023
1 parent 5155815 commit 7805677
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ exclude = ["HomebrewFormula"]

[dependencies]
arboard = "3.2.0"
atty = "0.2.14"
clap = { version = "4.2.1", features = ["derive"] }
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use arboard::Clipboard;
use std::fs::File;
use std::io::Read;
use std::process;
use std::io::{self, Read};
use atty::Stream;

#[derive(Debug)]
pub struct Query {
Expand All @@ -14,7 +15,19 @@ impl Query {

let source = match args.next() {
Some(arg) => arg,
None => return Err("No source to copy from"),
None => {
if atty::is(Stream::Stdout) && atty::is(Stream::Stderr) && atty::isnt(Stream::Stdin) {
let mut buffer = io::stdin();
let mut contents = String::new();
while let Ok(n) = buffer.read_to_string(&mut contents) {
if n == 0 {break;}
}
cpy(&contents);
process::exit(1);
}else{
return Err("No source to copy from");
}
},
};

Ok(Query { source })
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
)]
struct Zp {
///Name of the file to copy from.
file_name: String,
file_name: Vec<String>,
}

fn main() {
Expand Down

0 comments on commit 7805677

Please sign in to comment.