Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = ["/.github", "/img"]

[dependencies]
ansi-to-tui = "7.0.0"
arboard = "3.6.1"
arboard = { version = "3.6.1", features = ["wayland-data-control"] }
base64 = "0.22.1"
chrono = "0.4.42"
clap = { version = "4.5.53", features = ["derive"] }
Expand Down
22 changes: 18 additions & 4 deletions src/external.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::process::Command;
use std::{cell::RefCell, process::Command};

use arboard::Clipboard;

Expand All @@ -7,10 +7,24 @@ const USER_COMMAND_FIRST_PARENT_HASH_MARKER: &str = "{{first_parent_hash}}";
const USER_COMMAND_AREA_WIDTH_MARKER: &str = "{{area_width}}";
const USER_COMMAND_AREA_HEIGHT_MARKER: &str = "{{area_height}}";

thread_local! {
static CLIPBOARD: RefCell<Option<Clipboard>> = const { RefCell::new(None) };
}

pub fn copy_to_clipboard(value: String) -> Result<(), String> {
Clipboard::new()
.and_then(|mut c| c.set_text(value))
.map_err(|e| format!("Failed to copy to clipboard: {e:?}"))
CLIPBOARD.with_borrow_mut(|clipboard| {
if clipboard.is_none() {
*clipboard = Clipboard::new()
.map(Some)
.map_err(|e| format!("Failed to create clipboard: {e:?}"))?;
}

clipboard
.as_mut()
.expect("The clipboard should have been initialized above")
.set_text(value)
.map_err(|e| format!("Failed to copy to clipboard: {e:?}"))
})
}

pub fn exec_user_command(
Expand Down