Skip to content

Commit

Permalink
clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChurchTao committed Mar 7, 2024
1 parent 4992f2e commit c655a08
Show file tree
Hide file tree
Showing 17 changed files with 2,199 additions and 2,198 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ on:
- "README.md"

jobs:
rustfmt:
runs-on: ubuntu-22.04
steps:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
- uses: actions/checkout@v4
- name: Check formatting
run: cargo fmt --all -- --check

clippy:
needs: rustfmt
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
12 changes: 6 additions & 6 deletions examples/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use clipboard_rs::{Clipboard, ClipboardContext};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);

let buffer = ctx.get_buffer("public.html").unwrap();
let buffer = ctx.get_buffer("public.html").unwrap();

let string = String::from_utf8(buffer).unwrap();
let string = String::from_utf8(buffer).unwrap();

println!("{}", string);
println!("{}", string);
}
26 changes: 13 additions & 13 deletions examples/files.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use clipboard_rs::{Clipboard, ClipboardContext, ContentFormat};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let ctx = ClipboardContext::new().unwrap();

// change the file paths to your own
// let files = vec![
// "file:///home/parallels/clipboard-rs/Cargo.toml".to_string(),
// "file:///home/parallels/clipboard-rs/CHANGELOG.md".to_string(),
// ];
// change the file paths to your own
// let files = vec![
// "file:///home/parallels/clipboard-rs/Cargo.toml".to_string(),
// "file:///home/parallels/clipboard-rs/CHANGELOG.md".to_string(),
// ];

// ctx.set_files(files).unwrap();
// ctx.set_files(files).unwrap();

let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let types = ctx.available_formats().unwrap();
println!("{:?}", types);

let has = ctx.has(ContentFormat::Files);
println!("has_files={}", has);
let has = ctx.has(ContentFormat::Files);
println!("has_files={}", has);

let files = ctx.get_files().unwrap();
println!("{:?}", files);
let files = ctx.get_files().unwrap();
println!("{:?}", files);
}
26 changes: 13 additions & 13 deletions examples/helloworld.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use clipboard_rs::{Clipboard, ClipboardContext, ContentFormat};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);

let has_rtf = ctx.has(ContentFormat::Rtf);
println!("has_rtf={}", has_rtf);
let has_rtf = ctx.has(ContentFormat::Rtf);
println!("has_rtf={}", has_rtf);

let rtf = ctx.get_rich_text().unwrap();
let rtf = ctx.get_rich_text().unwrap();

println!("rtf={}", rtf);
println!("rtf={}", rtf);

let has_html = ctx.has(ContentFormat::Html);
println!("has_html={}", has_html);
let has_html = ctx.has(ContentFormat::Html);
println!("has_html={}", has_html);

let html = ctx.get_html().unwrap();
let html = ctx.get_html().unwrap();

println!("html={}", html);
println!("html={}", html);

let content = ctx.get_text().unwrap();
let content = ctx.get_text().unwrap();

println!("txt={}", content);
println!("txt={}", content);
}
14 changes: 7 additions & 7 deletions examples/image.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use clipboard_rs::{common::RustImage, Clipboard, ClipboardContext};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);

let img = ctx.get_image().unwrap();
let img = ctx.get_image().unwrap();

img.save_to_path("/tmp/test.png").unwrap();
img.save_to_path("/tmp/test.png").unwrap();

let resize_img = img.thumbnail(300, 300).unwrap();
let resize_img = img.thumbnail(300, 300).unwrap();

resize_img.save_to_path("/tmp/test_thumbnail.png").unwrap();
resize_img.save_to_path("/tmp/test_thumbnail.png").unwrap();
}
32 changes: 16 additions & 16 deletions examples/multi.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use clipboard_rs::{
common::ContentData, Clipboard, ClipboardContent, ClipboardContext, ContentFormat,
common::ContentData, Clipboard, ClipboardContent, ClipboardContext, ContentFormat,
};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let ctx = ClipboardContext::new().unwrap();

let contents: Vec<ClipboardContent> = vec![
ClipboardContent::Text("hell@$#%^&U都98好的😊o Rust!!!".to_string()),
ClipboardContent::Rtf("\x1b[1m\x1b[4m\x1b[31mHello, Rust!\x1b[0m".to_string()),
ClipboardContent::Html("<html><body><h1>Hello, Rust!</h1></body></html>".to_string()),
];
let contents: Vec<ClipboardContent> = vec![
ClipboardContent::Text("hell@$#%^&U都98好的😊o Rust!!!".to_string()),
ClipboardContent::Rtf("\x1b[1m\x1b[4m\x1b[31mHello, Rust!\x1b[0m".to_string()),
ClipboardContent::Html("<html><body><h1>Hello, Rust!</h1></body></html>".to_string()),
];

ctx.set(contents).unwrap();
ctx.set(contents).unwrap();

let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let types = ctx.available_formats().unwrap();
println!("{:?}", types);

let read = ctx
.get(&[ContentFormat::Text, ContentFormat::Rtf, ContentFormat::Html])
.unwrap();
let read = ctx
.get(&[ContentFormat::Text, ContentFormat::Rtf, ContentFormat::Html])
.unwrap();

for c in read {
println!("{}", c.as_str().unwrap());
}
for c in read {
println!("{}", c.as_str().unwrap());
}
}
28 changes: 14 additions & 14 deletions examples/watch_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use clipboard_rs::{Clipboard, ClipboardContext, ClipboardWatcher, ClipboardWatch
use std::{thread, time::Duration};

fn main() {
let ctx = ClipboardContext::new().unwrap();
let mut watcher = ClipboardWatcherContext::new().unwrap();
let ctx = ClipboardContext::new().unwrap();
let mut watcher = ClipboardWatcherContext::new().unwrap();

watcher.add_handler(Box::new(move || {
let content = ctx.get_text().unwrap();
println!("read:{}", content);
}));
watcher.add_handler(Box::new(move || {
let content = ctx.get_text().unwrap();
println!("read:{}", content);
}));

let watcher_shutdown = watcher.get_shutdown_channel();
let watcher_shutdown = watcher.get_shutdown_channel();

thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
println!("stop watch!");
watcher_shutdown.stop();
});
thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
println!("stop watch!");
watcher_shutdown.stop();
});

println!("start watch!");
watcher.start_watch();
println!("start watch!");
watcher.start_watch();
}
4 changes: 4 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hard_tabs = true
use_field_init_shorthand = true
use_try_shorthand = true
reorder_imports = true
Loading

0 comments on commit c655a08

Please sign in to comment.