More improvements
This commit is contained in:
parent
40e3e94b0b
commit
25e67b760b
3 changed files with 57 additions and 108 deletions
54
examples/big_file.rs
Normal file
54
examples/big_file.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use rand::distributions::{Alphanumeric, Distribution};
|
||||
use window_clipboard::Clipboard;
|
||||
use winit::{
|
||||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::WindowBuilder,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let data: String = Alphanumeric
|
||||
.sample_iter(&mut rng)
|
||||
.take(10_000_000)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
|
||||
let window = WindowBuilder::new()
|
||||
.with_title("Press G to start the test!")
|
||||
.build(&event_loop)
|
||||
.unwrap();
|
||||
|
||||
let mut clipboard =
|
||||
Clipboard::connect(&window).expect("Connect to clipboard");
|
||||
|
||||
clipboard.write(data.clone()).unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| match event {
|
||||
Event::WindowEvent {
|
||||
event:
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
virtual_keycode: Some(VirtualKeyCode::G),
|
||||
state: ElementState::Released,
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
let new_data = clipboard.read().expect("Read data");
|
||||
assert_eq!(data, new_data, "Data is equal");
|
||||
println!("Data copied successfully!");
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
||||
_ => *control_flow = ControlFlow::Wait,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue