Skip to content

Commit f642982

Browse files
committed
Make clipboard an optional feature.
1 parent b938e89 commit f642982

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3737
walkdir = "2.4.0"
3838
data-encoding = "2.6.0"
3939
n0-future = "0.1.2"
40-
arboard = "3.4.1"
40+
arboard = { version = "3.4.1", optional = true }
4141

4242
[dev-dependencies]
4343
duct = "0.13.6"
4444
nix = { version = "0.29", features = ["signal", "process"] }
4545
rand = "0.8.5"
4646
serde_json = "1.0.108"
4747
tempfile = "3.8.1"
48+
49+
[features]
50+
clipboard = ["dep:arboard"]
51+
default = []

src/main.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Command line arguments.
22
33
use anyhow::Context;
4+
#[cfg(feature = "clipboard")]
45
use arboard::Clipboard;
56
use clap::{
67
error::{ContextKind, ErrorKind},
78
CommandFactory, Parser, Subcommand,
89
};
9-
use console::{style, Key, Term};
10+
use console::style;
1011
use data_encoding::HEXLOWER;
1112
use futures_buffered::BufferedStreamExt;
1213
use indicatif::{
@@ -202,6 +203,7 @@ pub struct SendArgs {
202203
pub common: CommonArgs,
203204

204205
/// Store the receive command in the clipboard.
206+
#[cfg(feature = "clipboard")]
205207
#[clap(short = 'c', long)]
206208
pub clipboard: bool,
207209
}
@@ -652,20 +654,25 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
652654
println!("to get this data, use");
653655
println!("sendme receive {}", ticket);
654656

655-
// Add command to the clipboard
656-
if args.clipboard {
657-
add_to_clipboard(&ticket);
658-
}
657+
#[cfg(feature = "clipboard")]
658+
{
659+
use console::{Key, Term};
659660

660-
let _keyboard = tokio::task::spawn(async move {
661-
let term = Term::stdout();
662-
println!("press c to copy command to clipboard, or use the --clipboard argument");
663-
loop {
664-
if let Ok(Key::Char('c')) = term.read_key() {
665-
add_to_clipboard(&ticket);
666-
}
661+
// Add command to the clipboard
662+
if args.clipboard {
663+
add_to_clipboard(&ticket);
667664
}
668-
});
665+
666+
let _keyboard = tokio::task::spawn(async move {
667+
let term = Term::stdout();
668+
println!("press c to copy command to clipboard, or use the --clipboard argument");
669+
loop {
670+
if let Ok(Key::Char('c')) = term.read_key() {
671+
add_to_clipboard(&ticket);
672+
}
673+
}
674+
});
675+
}
669676

670677
tokio::signal::ctrl_c().await?;
671678

@@ -678,6 +685,7 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
678685
Ok(())
679686
}
680687

688+
#[cfg(feature = "clipboard")]
681689
fn add_to_clipboard(ticket: &BlobTicket) {
682690
let clipboard = Clipboard::new();
683691
match clipboard {

0 commit comments

Comments
 (0)