Skip to content

Commit

Permalink
fix: Added special handling for clipboard failures on Linux
Browse files Browse the repository at this point in the history
This hopefully points users to #8
  • Loading branch information
asasine committed May 23, 2024
1 parent 8cc160a commit 3a8e1dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 3 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 @@ -10,6 +10,7 @@ license = "MIT"
categories = ["command-line-utilities", "text-processing"]

[dependencies]
anstyle = "1.0.7"
arboard = "3.4"
clap = { version = "4.5", features = ["derive", "unicode"] }
human-panic = "2.0"
Expand Down
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ fn main() {
println!("{}", output);

if !args.no_copy {
let mut clipboard = Clipboard::new().expect("Failed to access clipboard");
clipboard
.set_text(output)
.expect("Failed to copy to clipboard.");

println!("Copied to clipboard.");
match Clipboard::new() {
Ok(mut clipboard) => {
clipboard
.set_text(output)
.expect("Failed to copy to clipboard.");
println!("Copied to clipboard.");
}
Err(e) => {
if cfg!(target_os = "linux") {
let yellow = anstyle::AnsiColor::Yellow.on_default();
eprintln!("\n{yellow}Looks like you're experiencing https://github.com/asasine/spongebob/issues/8. Clipboard support on Linux is currently unreliable. In the meantime, try piping to wl-copy from the wl-clipboard package or copying from your terminal above.{yellow:#}");
eprintln!("\nIf you can, please add a 👍 or comment to https://github.com/asasine/spongebob/issues/8 so I can prioritize fixing this.\n");
}

panic!("Failed to access clipboard: {}", e)
}
}
}
}

Expand Down

0 comments on commit 3a8e1dd

Please sign in to comment.