From 79e23bb70ed7fb756199770d10e3a3abe730d1b5 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Fri, 30 Nov 2018 16:55:47 -0800 Subject: [PATCH] Update dependencies --- Cargo.toml | 6 +++--- examples/progress.rs | 10 ++++++---- examples/vpv.rs | 8 +++++--- src/backend/blt.rs | 14 +++++++++----- src/backend/curses/n.rs | 6 ++++-- src/backend/curses/pan.rs | 2 +- src/backend/dummy.rs | 10 +++++++--- src/backend/resize.rs | 6 +++--- src/backend/termion.rs | 15 +++++++++------ src/cursive.rs | 26 ++++++++++++++------------ 10 files changed, 61 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 10ff013..7a95584 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ unicode-width = "0.1" xi-unicode = "0.1" libc = "0.2" term_size = { version = "0.3", optional = true } -crossbeam-channel = "0.2" +crossbeam-channel = "0.3" [dependencies.num] default-features = false @@ -55,7 +55,7 @@ version = "0.16" [dependencies.pulldown-cmark] default-features = false optional = true -version = "0.1" +version = "0.2" [dependencies.termion] optional = true @@ -65,7 +65,7 @@ version = "1.5" version = "0.1" [dev-dependencies] -rand = "0.5" +rand = "0.6" pretty-bytes = "0.2" [features] diff --git a/examples/progress.rs b/examples/progress.rs index 1963587..21cd3cf 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -52,7 +52,7 @@ fn phase_1(s: &mut Cursive) { fake_load(n_max, &counter); // When we're done, send a callback through the channel - cb.send(Box::new(coffee_break)); + cb.send(Box::new(coffee_break)).unwrap(); }) .full_width(), )); @@ -110,7 +110,7 @@ fn phase_2(s: &mut Cursive) { } } - cb.send(Box::new(final_step)); + cb.send(Box::new(final_step)).unwrap(); }); } @@ -124,8 +124,10 @@ fn final_step(s: &mut Cursive) { TextView::new( "Time travel was a success!\n\ We went forward a few seconds!!", - ).center(), - ).button("That's it?", |s| s.quit()), + ) + .center(), + ) + .button("That's it?", |s| s.quit()), ); } diff --git a/examples/vpv.rs b/examples/vpv.rs index 825cd55..50b693d 100644 --- a/examples/vpv.rs +++ b/examples/vpv.rs @@ -65,7 +65,7 @@ fn main() { } // When we're done, shut down the application - cb_sink.send(Box::new(|s: &mut Cursive| s.quit())); + cb_sink.send(Box::new(|s: &mut Cursive| s.quit())).unwrap(); }); // Add a single view: progress status @@ -112,8 +112,10 @@ fn main() { (0, 2), &format!("Speed: {}/s", convert(speed)), ); - }).fixed_size((25, 3)), - ).with(|l| { + }) + .fixed_size((25, 3)), + ) + .with(|l| { // If we have a file length, add a progress bar if let Some(len) = len { l.add_child( diff --git a/src/backend/blt.rs b/src/backend/blt.rs index 18a476a..afbdeb2 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -329,8 +329,12 @@ impl backend::Backend for Backend { thread::spawn(move || { for _ in input_requests { match receiver.recv() { - None => return, - Some(event) => event_sink.send(event), + Err(_) => return, + Ok(event) => { + if event_sink.send(event).is_err() { + return; + } + } } } }); @@ -340,7 +344,7 @@ impl backend::Backend for Backend { match input_request { backend::InputRequest::Peek => { let event = self.parse_next(); - self.inner_sender.send(event); + self.inner_sender.send(event).unwrap(); } backend::InputRequest::Block => { let timeout = Duration::from_millis(30); @@ -348,11 +352,11 @@ impl backend::Backend for Backend { let start = Instant::now(); while start.elapsed() < timeout { if let Some(event) = self.parse_next() { - self.inner_sender.send(Some(event)); + self.inner_sender.send(Some(event)).unwrap(); return; } } - self.inner_sender.send(Some(Event::Refresh)); + self.inner_sender.send(Some(Event::Refresh)).unwrap(); } } } diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 43ba48d..e7835bd 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -350,7 +350,9 @@ impl backend::Backend for Backend { } // Do the actual polling & parsing. - event_sink.send(parser.parse_next()); + if event_sink.send(parser.parse_next()).is_err() { + return; + } } // The request channel is closed, which means Cursive has been // dropped, so stop the resize-detection thread as well. @@ -488,7 +490,7 @@ where fn initialize_keymap() -> HashMap { // First, define the static mappings. - let mut map = hashmap!{ + let mut map = hashmap! { // Value sent by ncurses when nothing happens -1 => Event::Refresh, diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 5002b32..3d1b560 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -484,7 +484,7 @@ impl backend::Backend for Backend { input_parser.window.timeout(-1); } } - event_sink.send(input_parser.parse_next()); + event_sink.send(input_parser.parse_next()).unwrap(); } running.store(false, Ordering::Relaxed); }); diff --git a/src/backend/dummy.rs b/src/backend/dummy.rs index c8444ac..4cd644a 100644 --- a/src/backend/dummy.rs +++ b/src/backend/dummy.rs @@ -44,7 +44,7 @@ impl backend::Backend for Backend { } fn prepare_input(&mut self, _input_request: backend::InputRequest) { - self.inner_sender.send(Some(Event::Exit)); + self.inner_sender.send(Some(Event::Exit)).unwrap(); } fn start_input_thread( @@ -56,8 +56,12 @@ impl backend::Backend for Backend { thread::spawn(move || { for _ in input_requests { match receiver.recv() { - None => return, - Some(event) => event_sink.send(event), + Err(_) => return, + Ok(event) => { + if event_sink.send(event).is_err() { + return; + } + } } } }); diff --git a/src/backend/resize.rs b/src/backend/resize.rs index ee04b0e..0695be5 100644 --- a/src/backend/resize.rs +++ b/src/backend/resize.rs @@ -33,21 +33,21 @@ pub fn start_resize_thread( needs_resize.store(true, Ordering::Relaxed); } - resize_sender.send(Some(Event::WindowResize)); + resize_sender.send(Some(Event::WindowResize)).unwrap(); // We've sent the message. // This means Cursive was listening, and will now soon be sending a new request. // This means the input thread accepted a request, but hasn't sent a message yet. // So we KNOW the input thread is not waiting for a new request. // We sent an event for free, so pay for it now by consuming a request - while let Some(InputRequest::Peek) = resize_requests.recv() { + while let Ok(InputRequest::Peek) = resize_requests.recv() { // At this point Cursive will now listen for input. // There is a chance the input thread will send his event before us. // But without some extra atomic flag, it'd be hard to know. // So instead, keep sending `None` // Repeat until we receive a blocking call - resize_sender.send(None); + resize_sender.send(None).unwrap(); } } } diff --git a/src/backend/termion.rs b/src/backend/termion.rs index 1d333c2..c2bc4f6 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -61,7 +61,10 @@ impl InputParser { for _ in request_receiver { let event: Result = events.next().unwrap(); - input_sender.send(event.unwrap()); + + if input_sender.send(event.unwrap()).is_err() { + return; + } } }); @@ -78,7 +81,7 @@ impl InputParser { /// If we were already expecting input, this is a NO-OP. fn request(&mut self) { if !self.event_due { - self.requests.send(()); + self.requests.send(()).unwrap(); self.event_due = true; } } @@ -89,10 +92,10 @@ impl InputParser { let timeout = ::std::time::Duration::from_millis(10); let input = select! { - recv(self.input, input) => { + recv(self.input) -> input => { input } - recv(crossbeam_channel::after(timeout)) => return None, + recv(crossbeam_channel::after(timeout)) -> _ => return None, }; // We got what we came for. @@ -316,10 +319,10 @@ impl backend::Backend for Backend { for req in input_request { match req { backend::InputRequest::Peek => { - event_sink.send(parser.peek()); + event_sink.send(parser.peek()).unwrap(); } backend::InputRequest::Block => { - event_sink.send(Some(parser.next_event())); + event_sink.send(Some(parser.next_event())).unwrap(); } } } diff --git a/src/cursive.rs b/src/cursive.rs index 69154c6..9f57f84 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -87,10 +87,7 @@ impl Default for Cursive { } } -#[cfg(all( - not(feature = "termion-backend"), - feature = "pancurses-backend" -))] +#[cfg(all(not(feature = "termion-backend"), feature = "pancurses-backend"))] impl Default for Cursive { fn default() -> Self { Self::pancurses() @@ -206,7 +203,7 @@ impl Cursive { /// siv.set_fps(10); /// /// // quit() will be called during the next event cycle - /// siv.cb_sink().send(Box::new(|s: &mut Cursive| s.quit())); + /// siv.cb_sink().send(Box::new(|s: &mut Cursive| s.quit())).unwrap(); /// # } /// ``` /// @@ -607,7 +604,7 @@ impl Cursive { select! { // Skip to input if nothing is ready default => (), - recv(self.cb_source, cb) => return Some(Interruption::Callback(cb.unwrap())), + recv(self.cb_source) -> cb => return Some(Interruption::Callback(cb.unwrap())), } // No callback? Check input then @@ -616,8 +613,11 @@ impl Cursive { return None; } - self.input_trigger.send(backend::InputRequest::Peek); + self.input_trigger + .send(backend::InputRequest::Peek) + .unwrap(); self.backend.prepare_input(backend::InputRequest::Peek); + self.event_source.recv().unwrap().map(Interruption::Event) } @@ -626,7 +626,9 @@ impl Cursive { /// If `peek` is `true`, return `None` immediately if nothing is ready. fn poll(&mut self) -> Option { if !self.expecting_event { - self.input_trigger.send(backend::InputRequest::Block); + self.input_trigger + .send(backend::InputRequest::Block) + .unwrap(); self.backend.prepare_input(backend::InputRequest::Block); self.expecting_event = true; } @@ -639,16 +641,16 @@ impl Cursive { }; select! { - recv(self.event_source, event) => { + recv(self.event_source) -> event => { // Ok, we processed the event. self.expecting_event = false; event.unwrap().map(Interruption::Event) }, - recv(self.cb_source, cb) => { - cb.map(Interruption::Callback) + recv(self.cb_source) -> cb => { + cb.ok().map(Interruption::Callback) }, - recv(crossbeam_channel::after(timeout)) => { + recv(crossbeam_channel::after(timeout)) -> _ => { Some(Interruption::Timeout) } }