Skip to content

Commit a517ac5

Browse files
committed
Make clipboard an optional feature.
1 parent 2bed36f commit a517ac5

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
@@ -35,7 +35,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3535
walkdir = "2.4.0"
3636
data-encoding = "2.6.0"
3737
n0-future = "0.1.2"
38-
arboard = "3.4.1"
38+
arboard = { version = "3.4.1", optional = true }
3939
hex = "0.4.3"
4040

4141
[dev-dependencies]
@@ -44,3 +44,7 @@ nix = { version = "0.29", features = ["signal", "process"] }
4444
rand = "0.8.5"
4545
serde_json = "1.0.108"
4646
tempfile = "3.8.1"
47+
48+
[features]
49+
clipboard = ["dep:arboard"]
50+
default = ["clipboard"]

src/main.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use std::{
1010
};
1111

1212
use anyhow::Context;
13+
#[cfg(feature = "clipboard")]
1314
use arboard::Clipboard;
1415
use clap::{
1516
error::{ContextKind, ErrorKind},
1617
CommandFactory, Parser, Subcommand,
1718
};
18-
use console::{style, Key, Term};
19+
use console::style;
1920
use data_encoding::HEXLOWER;
2021
use futures_buffered::BufferedStreamExt;
2122
use indicatif::{
@@ -216,6 +217,7 @@ pub struct SendArgs {
216217
pub common: CommonArgs,
217218

218219
/// Store the receive command in the clipboard.
220+
#[cfg(feature = "clipboard")]
219221
#[clap(short = 'c', long)]
220222
pub clipboard: bool,
221223
}
@@ -741,20 +743,25 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
741743
println!("to get this data, use");
742744
println!("sendme receive {ticket}");
743745

744-
// Add command to the clipboard
745-
if args.clipboard {
746-
add_to_clipboard(&ticket);
747-
}
746+
#[cfg(feature = "clipboard")]
747+
{
748+
use console::{Key, Term};
748749

749-
let _keyboard = tokio::task::spawn(async move {
750-
let term = Term::stdout();
751-
println!("press c to copy command to clipboard, or use the --clipboard argument");
752-
loop {
753-
if let Ok(Key::Char('c')) = term.read_key() {
754-
add_to_clipboard(&ticket);
755-
}
750+
// Add command to the clipboard
751+
if args.clipboard {
752+
add_to_clipboard(&ticket);
756753
}
757-
});
754+
755+
let _keyboard = tokio::task::spawn(async move {
756+
let term = Term::stdout();
757+
println!("press c to copy command to clipboard, or use the --clipboard argument");
758+
loop {
759+
if let Ok(Key::Char('c')) = term.read_key() {
760+
add_to_clipboard(&ticket);
761+
}
762+
}
763+
});
764+
}
758765

759766
tokio::signal::ctrl_c().await?;
760767

@@ -771,6 +778,7 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
771778
Ok(())
772779
}
773780

781+
#[cfg(feature = "clipboard")]
774782
fn add_to_clipboard(ticket: &BlobTicket) {
775783
let clipboard = Clipboard::new();
776784
match clipboard {

0 commit comments

Comments
 (0)