Code Monkey home page Code Monkey logo

rust-clipboard's Introduction

rust-clipboard

rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard.
It has been tested on Windows, Mac OSX, GNU/Linux, and FreeBSD. It is used in Mozilla Servo.

Appveyor Build Status Travis Build Status

Prerequisites

On Linux you need the x11 library, install it with something like:

sudo apt-get install xorg-dev

Example

extern crate clipboard;

use clipboard::ClipboardProvider;
use clipboard::ClipboardContext;

fn example() {
    let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
    println!("{:?}", ctx.get_contents());
    ctx.set_contents("some string".to_owned()).unwrap();
}

API

The ClipboardProvider trait has the following functions:

fn new() -> Result<Self, Box<Error>>;
fn get_contents(&mut self) -> Result<String, Box<Error>>;
fn set_contents(&mut self, String) -> Result<(), Box<Error>>;

ClipboardContext is a type alias for one of {WindowsClipboardContext, OSXClipboardContext, X11ClipboardContext, NopClipboardContext}, all of which implement ClipboardProvider. Which concrete type is chosen for ClipboardContext depends on the OS (via conditional compilation).

License

rust-clipboard is dual-licensed under MIT and Apache2.

rust-clipboard's People

Contributors

adenilson avatar akosthekiss avatar alexheretic avatar aweinstock314 avatar booyaa avatar daggerbot avatar dashdashzako avatar doumanash avatar est31 avatar fabricedesre avatar frewsxcv avatar iceiix avatar kindlychung avatar mathphreak avatar mbrubeck avatar metajack avatar ms2ger avatar nox avatar paulrouget avatar quininer avatar rickycodes avatar simonsapin avatar ssheldon avatar tkerber avatar uk992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rust-clipboard's Issues

Clipboard is cleared when the process exits on Linux

Please consider the following code:

fn main() {
    let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
    ctx.set_contents("some string".to_owned()).unwrap();
    // Clipboard is "some string"
} // Clipboard is empty after exit

Binary clipboard

Being able to read the clipboard as a vector or slice of u8s would be extremely useful to anyone who needs to work with the clipboard not just with strings.

I know this is feasible in Windows, and I think it can be done in macOS (from what I read of the current implementation), but I don't know about in X11.

target_os="linux" prevents rust-clipboard from being used in the BSD's where it works perfectly.

Hi,

[target.'cfg(target_os = "linux")'.dependencies] on Cargo.toml
and
#[cfg(target_os="linux")] on lib.rs

prevents rust-clipboard from working on the BSD's.

If you change to
[target.'cfg(target_os = "unix")'.dependencies]
Cargo.toml

#[cfg(target_os="unix")]
lib.rs

It will work on both Linux and BSD's.

I tested several times (by cloning, changing to unix and then altering the Cargo.toml of the project I wanted to build to use the path, for example in https://amp.rs/) and rust-clipboard works perfectly on FreeBSD.

I can send a PR if you want.

EDIT: In alternative, because I only tested in FreeBSD I can make a PR with entries for target_os="freebsd"

Relicense under dual Apache2/MIT

It would be cool if you could relicense under the Apache2/MIT dual license.

The issue with Apache2 only crates is that they (most likely) can't be used by programs licensed under the LGPL license version 2 with static linking, or the GPL version 2 (with dynamic or static linking, or any other way).

Thank you πŸ‘Œ

This isn't an issue.
It's a thank you note, because you've made it trivially simple to communicate in both directions with the clipboard.
So, thank you to all the authors that have contributed to this crate!

Publish 0.1.2 to crates.io

The latest version on crates.io is 0.1.1, which unfortunately uses an older version of objc that will fail to compile after rust-lang/rust#34198.

objc was updated in #24, so all we have to do is push that change to crates.io and crater will stop reporting this crate as a regression :)

Getting Err value on provider.get_contents().unwrap()

The (WindowsClipboardContext) clipboard provider, on calling get_contents(), returns an Err value with code 0 and a message saying "The operation completed successfully." This makes it impossible to unwrap() the contents and use them although the clipboard provider appears to have successfully captured the clipboard.

Windows 10, Rust 2018 edition.

NSPasteboard#generalPasteboard returned null when called from macOS launchd Launch Daemon

Hi, so I'm not entirely sure if this is an issue with the library; I suspect it's more of a side-effect, but when acquiring a ClipboardContext on macOS from a launchd process like

let mut clipboard: ClipboardContext = ClipboardProvider::new().unwrap();

my program panics with the error NSPasteboard#generalPasteboard returned null. The program works OK when I execute it directly.

I am using the following daemon descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>myprogram</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>RUST_LOG</key>
        <string>debug</string>
        <key>RUST_BACKTRACE</key>
        <string>1</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
        <string>$HOME/.cargo/bin/myprogram</string>
    </array>
    <key>UserName</key>
    <string>$USER</string>
    <key>StandardOutPath</key>
    <string>$HOME/.myprogram/myprogram.log</string>
    <key>StandardErrorPath</key>
    <string>$HOME/.myprogram/myprogram.log</string>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

Apologies if this isn't strictly related to this library. Any insight would be greatly appreciated!

Error: load selection timeout

Hey,
I have a "load selection timeout" error when doing ctx.get_contents(). I am sorry I don't get much output, but happy to provide more (I am new to Rust).
I am using ubuntu 17.10, rust 1.23.
I could not find anything related to that on the issues.
Let me know what I can do to give you more information.
Cheers

Security advisory: please release with upgraded `xcb` dependencies

Solution: Upgrade xcb to >=1.0

See dependency tree below:

Crate:     xcb
Version:   0.8.2
Title:     Multiple soundness issues
Date:      2021-02-04
ID:        RUSTSEC-2021-0019
URL:       https://rustsec.org/advisories/RUSTSEC-2021-0019
Solution:  Upgrade to >=1.0
Dependency tree:
xcb 0.8.2
└── x11-clipboard 0.3.3
    └── clipboard 0.5.0
        └── tp-note 1.17.0

Dependency issue on official docker rust image

Hi

I tried to use this crate in a program in a docker linux image based on the official rust image rust:1.63
I got errors

error: linking with cc failed: exit status: 1
note: /usr/bin/ld: cannot find -lxcb-shape
          /usr/bin/ld: cannot find -lxcb-xfixes

I got told elsewhere to try installing
apt install libxcb-shape0-dev

This also failed and i got another similar error that led me to libxcb1

I installed this, and cargo claimed a succesful build but the program then failed at:
thread 'main' panicked at 'called Result::unwrap()on anErr value: XcbConn(ClosedParseErr)

reffering to:
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();

This compiles fine on my local machine (mac x86_64) but not on 5.10.104-linuxkit as the official rust linux image is based on

Please clarify maintenance status

This repository hasn't received any updates since February of 2019, nor have any issues or pull requests been replied to since then (that I could see). The last time this was asked, it was noted that it was, but just less active. However, a few months after that the dead period began. I also tried looking on Mozilla's Matrix server for areweinstock since the IRC server was closed, but did not find any users.

If reasonable, it would be ideal to get a full answer who have some level of ownership and past activity with this crate. So, @aweinstock314, @SimonSapin, @nox: Is this crate still maintained in any way? It is still specified in servo's cargo manifest but does not appear to be an ongoing concern.

Write a non-GPL'd X11ClipboardContext

Currently, X11ClipboardContext is a straightforward port of xclip, which is GPL2. That means that this crate has to be GPL2, which makes it unsuited to its original purpose (see servo/servo@ecabb18), as well as less likely to be adopted by the Rust ecosystem (e.g. https://github.com/jwilm/alacritty/blob/master/copypasta/src/x11.rs#L5-L6). The current licensing situation also seems potentially confusing (see issue #33). The current code also has some heisenbugs that seem to be a result of UB (see issue #25), but with nothing obvious jumping out, a rewrite also has a chance of fixing this.

https://tronche.com/gui/x/icccm/sec-2.html seems to be the primary documentation on what The Right Thing for the protocol should be.
http://invisible-island.net/xterm/xterm.html looks to have a permissive (BSD/MIT style) license, and is a real-world piece of code that can be referred to for how it's done in practice.

The overall architecture currently involves spawning threads instead of forking, which results in the clipboard not persisting past the end of the main thread. This was done due to potential deadlock concerns on systems that don't use pthread_atfork hooks in their malloc implementations, based on the comment at https://github.com/rust-lang/rust/blob/ee60afa09465cedfa08be04e59b6a8ccfd54685f/src/libstd/sys/unix/process/process_unix.rs#L114-L143. Now that the types have been refactored (X11ClipboardContext is a seperate type from ClipboardContext), it might make sense to fork-by-default, but leave an option in the constructor fall back to threads if anyone's experiencing deadlocks in practice (this could maybe use some more thought).

Another issue with the current code is that it doesn't correctly handle concurrent requests (it drops all subsequent ones, following xclip's design choices). Since the protocol can be treated as a state machine, it should be easy (from a not-ported-from-C perspective) to store a HashMap<RequestIdentifier /* probably *mut Window? */, RequestStateMachine> to handle concurrent requests. This sort of design will also facilitate adding bells-and-whistles like 2.2's "More advanced selection owners are free to maintain a history of the value of the selection and to respond to requests for the value of the selection during periods they owned it even though they do not own it now."

Rewriting X11ClipboardContext would fix the majority of the outstanding issues on this crate, and is a blocker for the remaining one (i.e. making a least-common-denominator API for typed data), as it doesn't make sense to duplicate the work of implementing that feature on code that's planned to be rewritten anyway.

Handling trailing \u{0} from the [Windows] clipboard

First, many thanks for clipboard. I'm very much a Rust newbie, and it's an important component of my first self-imposed training exercise.

Second, I have no idea how "appropriate" this suggestion is, so I won't be in an way miffed if you find it too special a case and close it as WontFix. So here goes:

Under some circumstances, but not always, Windows appears to append a null byte (I think) to the contents of the clipboard. The specific case I have found is when marking and copying from a command window.

I had marked and copied 2018.074.

My program rejected it (debug formatting): Date "2018.074\u{0}" is invalid.

Clearly I can tidy this up myself, but I wonder whether this would be more generally useful.

Can't run example on FreeBSD

> cargo run --example hello_world
.. <cut> ..

warning: `clipboard` (lib) generated 15 warnings
   Compiling clipboard v0.5.0 (/usr/home/xliiv/codespace/_tmp/rust-clipboard)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1b733kuccjd4fngh.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1by0g0ihopvvq3qq.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1cw0kftkiw71gl5z.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1dpn2bd4fdudjoyw.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1i5libu7qheck6me.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1kotqtiqyu1zmrd0.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1x92elnbnsofzwbz.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.1xzwf1frvwoq27me.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.2e7nrb2h40yd0nbf.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.2giyq4wzsoho6xyb.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.2isf7ay0nfomodjg.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.2o92tujfknrs2bpl.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.2ufdbxw1ato5d6hs.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.32h7zqi8tt180v0i.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.33yj691r27g0oyui.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.37sv2b8m7aw0na9k.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3a4e5urfkcxwwvpv.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3byqocsm7khaf9s9.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3emuz9c2toikagtx.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3kc2v2ktpwx3718q.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3l3sq2exj2wwi20x.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3ly7g1dmljj7n5yy.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.3njt8th6dfnq8jb3.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.417rl8heaf096omb.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.47o0p95xidxjzioc.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4frif1qt66j2vbsx.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4oycwzotsqx6l3fz.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4rycs9qdjy3xrjbu.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4s0pow7tfej57z4g.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4xg80segbbrt1eb.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.5cxw0c8glduit52d.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.5zta1gpwvqscd8o.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.ann6iy1igyut04o.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.cob6r43l604dffu.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.jnd5p4we5o8kwdc.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.lnv34qwtal4o7p0.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.m7qpez9qdtce6no.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.mtfkfu5iqe9udt2.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.w2bwne2cbn39eua.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.x7dypj4qe7wpiw8.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.yceqjj3zud07p27.rcgu.o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1.4bl793uiaxxbe0if.rcgu.o" "-Wl,--as-needed" "-L" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps" "-L" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-Wl,-Bstatic" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/libclipboard-ea45412651c61e5d.rlib" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/libx11_clipboard-20b73909393d4495.rlib" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/libxcb-4be31895522d3844.rlib" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/liblog-d141dfc4245c10fe.rlib" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/libcfg_if-c36d063572492454.rlib" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/deps/liblibc-6c4f2187495a3f8e.rlib" "-Wl,--start-group" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd-559def2745ea740e.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libpanic_unwind-370cd5974ac1f528.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libobject-3f70fb3d52df2100.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libmemchr-ff9d325945dbb3e1.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libaddr2line-15e6886f90bb2e2a.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libgimli-31ed3054339a0418.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_demangle-59d77492b1275b96.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd_detect-50ed39e83fca9250.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libhashbrown-ae1ba104983f279d.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libminiz_oxide-4f326a1e724f28af.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libadler-6dad2edc9fffc960.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_alloc-9a19d186cc9638dd.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libunwind-f141ec8e70eb17b0.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcfg_if-b1e321cf020c4daf.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liblibc-26d9065b5654606c.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liballoc-602c643ce77440db.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_core-ab43e47586270b72.rlib" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcore-a51716ebfee9a844.rlib" "-Wl,--end-group" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcompiler_builtins-a1266d41d2b323d0.rlib" "-Wl,-Bdynamic" "-lxcb" "-lxcb-render" "-lxcb-shape" "-lxcb-xfixes" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/home/xliiv/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-o" "/usr/home/xliiv/codespace/_tmp/rust-clipboard/target/debug/examples/hello_world-79d8fb229ab568b1" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: ld: error: unable to find library -lxcb
          ld: error: unable to find library -lxcb-render
          ld: error: unable to find library -lxcb-shape
          ld: error: unable to find library -lxcb-xfixes
          cc: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `clipboard` due to previous error

Any clue?

Update

Examples for x11-clipboard crate works

> cargo run --example paste
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/paste`
some-pasted-text⏎

Use enums instead of Box<Error> for failure

I've hard-forked this repository at https://github.com/fschutt/clipboard2 and changed it to return a ClipboardError enum. The problem with Box<Error> is basically that it erases all type information - the library user can only get the description, which isn't of much use except for debugging.

I've replaced all usage of Box<Error> with an error enum which is not only type-safe and more descriptive (the library use now knows why the function could fail), but also more performant (no dynamic dispatch). I'd be happy to contribute the changes back into this repo, but for now I'm using the hard fork (I'll credit your repository though, since large amounts of that repo isn't technically my code).

Shouldn't failure conditions return `Err`?

I looked at the source for nop_clipboard.rs, and this doesn't seem right:

impl ClipboardProvider for NopClipboardContext {
    fn new() -> Result<NopClipboardContext, Box<Error>> {
        Ok(NopClipboardContext)
    }
    fn get_contents(&mut self) -> Result<String, Box<Error>> {
        println!("Attempting to get the contents of the clipboard, which hasn't yet been \
                  implemented on this platform.");
        Ok("".to_string())
    }
    fn set_contents(&mut self, _: String) -> Result<(), Box<Error>> {
        println!("Attempting to set the contents of the clipboard, which hasn't yet been \
                  implemented on this platform.");
        Ok(())
    }
}

Shouldn't this return Err, not Ok? It's kind of a pain to deal with an error condition that indicates success

Can't set clipboard contents on Ubuntu 15.10

The following code seems to get the clipboard contents just fine, but it doesn't actually set it correctly. set_contents returns successfully; it just doesn't set anything.

extern crate clipboard;
use clipboard::*;

fn main() {
    let mut ctx = ClipboardContext::new().unwrap();
    match ctx.get_contents() {
        Ok(clip) => println!("{}", clip),
        Err(err) => println!("Error getting clip: {:?}", err),
    }
    match ctx.set_contents("A string set from rust".to_string()) {
        Ok(_) => println!("Set new string."),
        Err(err) => println!("Error setting string: {:?}", err),
    }
}

The output is just:

This is the correct content of my clipboard before running
Set new string.

But afterwards my clipboard is empty. How would I go about figuring out what's wrong?

Android support

I've tried to build a project for Android and it tried to link to xcb. Turns out this library depends on xcb :)

Is Android support planned and if not, could we add a compile_error! if the target platform is Android?

Can I use this crate in an MIT licensed project?

Hi,

GPL implies I have to distribute the sources of the whole project. But I can I still use an MIT license in my project if I use this crate? I've found this stackexchange question, and the accepted answers suggests that I have to use GPL:

> Because GeSHi is GPL, does my framework have to be GPL?

ANSWER: If you distribute your framework, then YES.

That seems a little bit weird to me though.

Prepare to update clipboard-win

Hello,

I started re-writing API for clipboard-win.
More or less i have unified it, added Clipboard class and improved a bit a way i was extracting clipboard data(using GlobalSize instead of strlen)

It is for now pre1 as i'm still considering a way to make API better and waiting for new version of winapi.
Feel free to take a look and have suggestions on API changes.

Compilation error on Linux

   Compiling clipboard v0.0.1 (file:///root/rust-clipboard)
src/x11_clipboard.rs:106:26: 106:123 error: use of unstable library feature 'collections': likely to be replaced by a more optimized extend
src/x11_clipboard.rs:106                     dest.push_all(unsafe { slice::from_raw_parts_mut(buffer, (pty_machsize as usize) / size_of::<u8>()) });
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/x11_clipboard.rs:106:26: 106:123 help: add #![feature(collections)] to the crate attributes to enable
src/x11_clipboard.rs:138:26: 138:123 error: use of unstable library feature 'collections': likely to be replaced by a more optimized extend
src/x11_clipboard.rs:138                     dest.push_all(unsafe { slice::from_raw_parts_mut(buffer, (pty_machsize as usize) / size_of::<u8>()) });
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/x11_clipboard.rs:138:26: 138:123 help: add #![feature(collections)] to the crate attributes to enable
error: aborting due to 2 previous errors
Could not compile `clipboard`.

To learn more, run the command again with --verbose.

set_contents doesnt work for me

hello.

i have a minimal example.

    use clipboard::ClipboardProvider;
    use clipboard::ClipboardContext;

    let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
    ctx.set_contents(String::from("hello")).unwrap();

this should copy to clipboard the string hello and then it should be pasteable with control-v everywhere.

actuall result: doesnt do anything (doesnt copy to clipboard), the clipboard is empty.

here is some neofetch:

                 `ooo/                   OS: Manjaro Linux x86_64
                `+oooo:                  Host: GL553VD 1.0
               `+oooooo:                 Kernel: 5.10.105-1-MANJARO
               -+oooooo+:                Uptime: 51 mins
             `/:-:++oooo+:               Packages: 1955 (pacman)
            `/++++/+++++++:              Shell: zsh 5.8.1
           `/++++++++++++++:             Resolution: 1920x1080
          `/+++ooooooooooooo/`           DE: Xfce 4.16
         ./ooosssso++osssssso+`          WM: Xfwm4
        .oossssso-````/ossssss+`         WM Theme: borderless-windows
       -osssssso.      :ssssssso.        Theme: Matcha-dark-aliz [GTK2], Adwaita [GTK3
      :osssssss/        osssso+++.       Icons: Papirus-Dark [GTK2], Adwaita [GTK3]
     /ossssssss/        +ssssooo/-       Terminal: tmux
   `/ossssso+/:-        -:/+osssso+-     CPU: Intel i7-7700HQ (8) @ 3.800GHz
  `+sso+:-`                 `.-/+oso:    GPU: Intel HD Graphics 630
 `++:.                           `-/+/   GPU: NVIDIA GeForce GTX 1050 Mobile
 .`                                 `/   Memory: 10703MiB / 15890MiB
                                         GPU Driver: ASUSTeK Computer Inc. Device [104

specs:

  • arch linux -> manjaro 22/23 Pahvo or later
  • kernel 5.10
  • xfce Desktop Environment

what am i missing guys? why it doesnt work?

my DE is using X11 and i saw this merge here that it was implemented for x11

Paste as HTML

I want to request this feature, as well as track the steps toward making it happen!

Proposal: ctx.get_contents_by_type(ClipboardType::HTML), Text, Image, etc.

Windows:

OS X:

  • This stack overflow answer suggests stringForType can be used on this platform. Not sure how that differs yet.

Linux:

  • A little out of my depth (X11).

0.4.3 broken on linux

Hey Linux is in the unix target_family, but it is not unix. 0.4.3 tests do not compile on Linux.

To be fair the main package does compile, but without functionality.

I'm surprised you don't have travis linux testing, at least compile.

error[E0432]: unresolved import `clipboard::x11_clipboard`
 --> examples/primary_selection.rs:5:16
  |
5 | use clipboard::x11_clipboard::{X11ClipboardContext, Primary};
  |                ^^^^^^^^^^^^^ Could not find `x11_clipboard` in `clipboard`

error: aborting due to previous error

error: Could not compile `clipboard`.
warning: build failed, waiting for other jobs to finish...
error: build failed

"cargo build" OK but "cargo build --release" not OK

Hello all,

First of all, thanks for your hard work on this library. It's awesome to see this type of library be cross-platform too !

I'm having a weird issue where I can set the clipboard contents after running cargo build (debug mode) but I can't if I run cargo build --release. I've created a sample project to demonstrate this:
https://github.com/conradkleinespel/rust-clipboard-issue

Steps to reproduce:

  • download the sample project,
  • run cargo build,
  • run ./target/debug/rust-clipboard-issue,
  • go to a text field and hit Ctrl-V (should work fine),
  • run cargo build --release instead of cargo build,
  • run ./target/release/rust-clipboard-issue,
  • go to a text field and hit Ctrl-V (should fail).

I'm testing on Arch Linux (with X server, not wayland).

Are you experiencing this problem to, by any chance ? Any clue on what could be the problem here ?

Thanks so much for taking the time to read this. Have a nice week.

Conrad

clipboard not compiling on Travis CI linux targets

Thanks for this crate, I'm using it for a terminal code snippets manager here. I'm having some issues building binaries for Linux using Travis, and the failure seems to be related to clipboard's xcb dependency. This is the error:

error: failed to run custom build command for `xcb v0.8.2`

Caused by:

  process didn't exit successfully: `/target/debug/build/xcb-642392b748273c1b/build-script-build` (exit code: 101)

--- stderr

thread 'main' panicked at 'Unable to find build dependency python3: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /cargo/registry/src/github.com-1ecc6299db9ec823/xcb-0.8.2/build.rs:67:26

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I've tried adding dependencies to the travis file (here) based on some other issues and pull requests from this repo, but no luck. This is the first time I'm trying something like this so maybe I've made a silly error somewhere, let me know if it's unrelated and I'll close this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.