Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Copy to clipboard unsuccessful #2028

Open
1 task done
ovv opened this issue May 17, 2024 · 6 comments · May be fixed by #2067
Open
1 task done

[Bug]: Copy to clipboard unsuccessful #2028

ovv opened this issue May 17, 2024 · 6 comments · May be fixed by #2067
Labels
bug Something isn't working

Comments

@ovv
Copy link

ovv commented May 17, 2024

What did you expect to happen?

Pressing ctrl-y in the search view should copy the selected line to the clipboard

What happened?

Pressing ctrl-y closes atuin but the clipboard content is not set

Atuin doctor output

atuin:
  version: 18.2.0
  sync:
    cloud: false
    records: true
    auto_sync: true
    last_sync: 2024-05-17 11:10:19.493442155 +00:00:00
shell:
  name: fish
  default: unknown
  plugins:
  - atuin
system:
  os: Fedora Linux
  arch: x86_64
  version: '39'
  disks:
  - name: /dev/mapper/luks-a71d0523-7b8b-4cc2-9d60-a73e65041027
    filesystem: btrfs
  - name: /dev/mapper/luks-a71d0523-7b8b-4cc2-9d60-a73e65041027
    filesystem: btrfs
  - name: /dev/nvme0n1p2
    filesystem: ext4
  - name: /dev/nvme0n1p1
    filesystem: vfat

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ovv ovv added the bug Something isn't working label May 17, 2024
@ovv
Copy link
Author

ovv commented May 17, 2024

Interestingly using this patch make it work. I'm quite confused how/why

diff --git a/crates/atuin/src/command/client/search/interactive.rs b/crates/atuin/src/command/client/search/interactive.rs
index 9185bc0f..5caedeb4 100644
--- a/crates/atuin/src/command/client/search/interactive.rs
+++ b/crates/atuin/src/command/client/search/interactive.rs
@@ -1174,7 +1174,8 @@ pub async fn history(
     any(target_os = "windows", target_os = "macos", target_os = "linux")
 ))]
 fn set_clipboard(s: String) {
-    cli_clipboard::set_contents(s).unwrap();
+    cli_clipboard::set_contents(s.to_owned()).unwrap();
+    assert_eq!(cli_clipboard::get_contents().unwrap(), s);
 }
 
 #[cfg(not(all(

@tessus
Copy link
Contributor

tessus commented May 21, 2024

I was not able to reproduce this on macOS.

@ellie
Copy link
Member

ellie commented May 22, 2024

I think this is only an issue on Linux. What window manager/graphical env are you using?

@ovv
Copy link
Author

ovv commented May 22, 2024

I think this is only an issue on Linux. What window manager/graphical env are you using?

I'm using KDE Plasma, it reproduces on plasma 5 and 6

The cli_clipboard crate documentation mention a different behavior on Linux.

This uses the platform default behavior for setting clipboard contents. Other users of the Wayland or X11 clipboard will only see the contents copied to the clipboard so long as the process copying to the clipboard exists. MacOS and Windows clipboard contents will stick around after your application exits.

I don't fully understand the so long as the process copying to the clipboard exists since it seems to work if the process doesn't exit instantly. This code work, removing the sleep makes it fail.

use cli_clipboard;
use std::time::Duration;
use std::thread::sleep;

fn main() {
    let the_string = "foobar";
    cli_clipboard::set_contents(the_string.to_owned()).unwrap();
    sleep(Duration::new(1, 0));
}

Looks like the bug is not directly related to atuin

@LecrisUT
Copy link
Contributor

LecrisUT commented May 30, 2024

Hi @ellie, I am working on packaging atuin for Fedora (now there is only 1 dependency left, guess which), and I've encountered errors when testing cli_clipboard. Upstream appears to encounter similar test failures. They also point to a few alternatives, primarily arboard and copypasta. The former seems to be the most active right now. Both are packaged right now, so it could be that these work better for linux. Will you consider trying either of these out?

@ellie
Copy link
Member

ellie commented May 30, 2024

I'd be pretty happy to switch to arboard - I'll likely get around to doing so fairly soon, unless anyone fancies making a PR

@LecrisUT LecrisUT linked a pull request May 31, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants