mirror of
https://github.com/1Password/arboard.git
synced 2025-07-07 13:25:18 +00:00
Renamed set/get_contents to set/get_text. Updated the license file structure.
This commit is contained in:
parent
07d080be58
commit
d40eb89df9
13 changed files with 50 additions and 80 deletions
|
@ -8,7 +8,7 @@ license = "MIT / Apache-2.0"
|
|||
keywords = ["clipboard"]
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
clipboard-win = "2.1"
|
||||
clipboard-win = "3.0"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc = "0.2"
|
||||
|
@ -16,4 +16,4 @@ objc_id = "0.1"
|
|||
objc-foundation = "0.1"
|
||||
|
||||
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies]
|
||||
x11-clipboard = "0.3"
|
||||
x11-clipboard = "0.5"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Apache License
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
|
@ -174,28 +175,3 @@ Apache License
|
|||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
21
LICENSE-MIT.txt
Normal file
21
LICENSE-MIT.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 The arboard contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
25
LICENSE.mit
25
LICENSE.mit
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2017 Avraham Weinstock
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
4
LICENSE.txt
Normal file
4
LICENSE.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Copyright (c) 2020 The arboard contributors
|
||||
|
||||
This software is licensed under either the MIT (see LICENSE-MIT.txt) license
|
||||
or the Apache 2.0 (see LICENSE-APACHE.txt) license at your option.
|
19
README.md
19
README.md
|
@ -1,12 +1,7 @@
|
|||
# rust-clipboard
|
||||
# arboard
|
||||
|
||||
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.
|
||||
|
||||
[](https://crates.io/crates/clipboard)
|
||||
[](https://ci.appveyor.com/project/aweinstock314/rust-clipboard)
|
||||
[](https://travis-ci.org/aweinstock314/rust-clipboard)
|
||||
This crate is a fork of rust-clipboard and a cross-platform library for getting and setting the contents of the OS-level clipboard.
|
||||
It adds wayland support
|
||||
|
||||
## Prerequisites
|
||||
|
||||
|
@ -26,8 +21,8 @@ use clipboard::ClipboardContext;
|
|||
|
||||
fn example() {
|
||||
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
|
||||
println!("{:?}", ctx.get_contents());
|
||||
ctx.set_contents("some string".to_owned()).unwrap();
|
||||
println!("{:?}", ctx.get_text());
|
||||
ctx.set_text("some string".to_owned()).unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -37,8 +32,8 @@ The `ClipboardProvider` trait has the following functions:
|
|||
|
||||
```rust
|
||||
fn new() -> Result<Self, Box<Error>>;
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>>;
|
||||
fn set_contents(&mut self, String) -> Result<(), Box<Error>>;
|
||||
fn get_text(&mut self) -> Result<String, Box<Error>>;
|
||||
fn set_text(&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).
|
||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
|
||||
let the_string = "Hello, world!";
|
||||
|
||||
ctx.set_contents(the_string.to_owned()).unwrap();
|
||||
ctx.set_text(the_string.to_owned()).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
use std::error::Error;
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub fn err(s: &str) -> Box<Error> {
|
||||
Box::<Error + Send + Sync>::from(s)
|
||||
|
@ -26,9 +27,7 @@ pub trait ClipboardProvider: Sized {
|
|||
// TODO: consider replacing Box<Error> with an associated type?
|
||||
fn new() -> Result<Self, Box<Error>>;
|
||||
/// Method to get the clipboard contents as a String
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>>;
|
||||
fn get_text(&mut self) -> Result<String, Box<Error>>;
|
||||
/// Method to set the clipboard contents as a String
|
||||
fn set_contents(&mut self, String) -> Result<(), Box<Error>>;
|
||||
// TODO: come up with some platform-agnostic API for richer types
|
||||
// than just strings (c.f. issue #31)
|
||||
fn set_text(&mut self, text: String) -> Result<(), Box<Error>>;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,6 @@ pub type ClipboardContext = nop_clipboard::NopClipboardContext;
|
|||
#[test]
|
||||
fn test_clipboard() {
|
||||
let mut ctx = ClipboardContext::new().unwrap();
|
||||
ctx.set_contents("some string".to_owned()).unwrap();
|
||||
assert!(ctx.get_contents().unwrap() == "some string");
|
||||
ctx.set_text("some string".to_owned()).unwrap();
|
||||
assert!(ctx.get_text().unwrap() == "some string");
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ impl ClipboardProvider for NopClipboardContext {
|
|||
fn new() -> Result<NopClipboardContext, Box<Error>> {
|
||||
Ok(NopClipboardContext)
|
||||
}
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>> {
|
||||
fn get_text(&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>> {
|
||||
fn set_text(&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(())
|
||||
|
|
|
@ -40,7 +40,7 @@ impl ClipboardProvider for OSXClipboardContext {
|
|||
let pasteboard: Id<Object> = unsafe { Id::from_ptr(pasteboard) };
|
||||
Ok(OSXClipboardContext { pasteboard: pasteboard })
|
||||
}
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>> {
|
||||
fn get_text(&mut self) -> Result<String, Box<Error>> {
|
||||
let string_class: Id<NSObject> = {
|
||||
let cls: Id<Class> = unsafe { Id::from_ptr(class("NSString")) };
|
||||
unsafe { transmute(cls) }
|
||||
|
@ -61,7 +61,7 @@ impl ClipboardProvider for OSXClipboardContext {
|
|||
Ok(string_array[0].as_str().to_owned())
|
||||
}
|
||||
}
|
||||
fn set_contents(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
fn set_text(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
let string_array = NSArray::from_vec(vec![NSString::from_str(&data)]);
|
||||
let _: usize = unsafe { msg_send![self.pasteboard, clearContents] };
|
||||
let success: bool = unsafe { msg_send![self.pasteboard, writeObjects:string_array] };
|
||||
|
|
|
@ -25,10 +25,10 @@ impl ClipboardProvider for WindowsClipboardContext {
|
|||
fn new() -> Result<Self, Box<Error>> {
|
||||
Ok(WindowsClipboardContext)
|
||||
}
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>> {
|
||||
fn get_text(&mut self) -> Result<String, Box<Error>> {
|
||||
Ok(get_clipboard_string()?)
|
||||
}
|
||||
fn set_contents(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
fn set_text(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
Ok(set_clipboard_string(&data)?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ where
|
|||
Ok(X11ClipboardContext(X11Clipboard::new()?, PhantomData))
|
||||
}
|
||||
|
||||
fn get_contents(&mut self) -> Result<String, Box<Error>> {
|
||||
fn get_text(&mut self) -> Result<String, Box<Error>> {
|
||||
Ok(String::from_utf8(self.0.load(
|
||||
S::atom(&self.0.getter.atoms),
|
||||
self.0.getter.atoms.utf8_string,
|
||||
|
@ -63,7 +63,7 @@ where
|
|||
)?)?)
|
||||
}
|
||||
|
||||
fn set_contents(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
fn set_text(&mut self, data: String) -> Result<(), Box<Error>> {
|
||||
Ok(self.0.store(
|
||||
S::atom(&self.0.setter.atoms),
|
||||
self.0.setter.atoms.utf8_string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue