GithubHelp home page GithubHelp logo

discretetom / clipboard-win Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doumanash/clipboard-win

0.0 1.0 0.0 164 KB

Rust win clipboard utilities

Home Page: https://crates.io/crates/clipboard-win

License: Boost Software License 1.0

Rust 100.00%

clipboard-win's Introduction

clipboard-win

Build Crates.io Docs.rs

This crate provide simple means to operate with Windows clipboard.

Note keeping Clipboard around:

In Windows Clipboard opens globally and only one application can set data onto format at the time.

Therefore as soon as operations are finished, user is advised to close Clipboard.

Clipboard

All read and write access to Windows clipboard requires user to open it.

Usage

Manually lock clipboard

use clipboard_win::{Clipboard, formats, Getter, Setter};

const SAMPLE: &str = "MY loli sample ^^";

let _clip = Clipboard::new_attempts(10).expect("Open clipboard");
formats::Unicode.write_clipboard(&SAMPLE).expect("Write sample");

let mut output = String::new();

assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Efficiently re-use buffer ;)
output.clear();
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Or take the same string twice?
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(format!("{0}{0}", SAMPLE), output);

Simplified API

use clipboard_win::{formats, get_clipboard, set_clipboard};

let text = "my sample ><";

set_clipboard(formats::Unicode, text).expect("To set clipboard");
//Type is necessary as string can be stored in various storages
let result: String = get_clipboard(formats::Unicode).expect("To set clipboard");
assert_eq!(result, text)

clipboard-win's People

Contributors

arturkovacs avatar complexspaces avatar doumanash avatar mchels avatar

Watchers

 avatar

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.