get_text

Function get_text 

Source
pub fn get_text() -> Result<String, &'static str>
Expand description

Reads the contents of the clipboard.

Supported platforms: Linux (with X server), Windows.

Under Linux you must have the program xsel installed. You can install it with your package manager.

§Examples

let backup = jabba_lib::jclipboard::get_text().unwrap();
let text = "hello";

jabba_lib::jclipboard::check();  // verify if your platform is supported

jabba_lib::jclipboard::set_text(text).unwrap();
println!("The text {:?} was pasted on the clipboard", text);

let read = jabba_lib::jclipboard::get_text().unwrap();
println!("Contents of the clipboard: {:?}", read);

assert_eq!(read, text);
jabba_lib::jclipboard::set_text(&backup).unwrap();
Examples found in repository?
examples/clipboard_short.rs (line 11)
3fn main() {
4    let text = "hello";
5
6    jclipboard::check(); // verify if your platform is supported
7
8    jclipboard::set_text(text).unwrap();
9    println!("The text {:?} was pasted on the clipboard", text);
10
11    let read = jclipboard::get_text().unwrap();
12    println!("Contents of the clipboard: {:?}", read);
13
14    assert_eq!(read, text);
15}
More examples
Hide additional examples
examples/clipboard.rs (line 10)
3fn main() {
4    jclipboard::check();
5
6    for &text in &["", "a", "aa", "hello", "world", "rust", "Éva"] {
7        jclipboard::set_text(text).unwrap();
8        println!("The text {:?} was pasted on the clipboard", text);
9
10        let read = jclipboard::get_text().unwrap();
11        println!("Contents of the clipboard: {:?}", read);
12        assert_eq!(read, text);
13        println!("---");
14    }
15}