Update dependencies

This commit is contained in:
Alexandre Bury 2018-11-30 16:55:47 -08:00
parent a6d9b46bf3
commit 79e23bb70e
10 changed files with 61 additions and 42 deletions

View File

@ -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]

View File

@ -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()),
);
}

View File

@ -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(

View File

@ -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();
}
}
}

View File

@ -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<i32, Event> {
// First, define the static mappings.
let mut map = hashmap!{
let mut map = hashmap! {
// Value sent by ncurses when nothing happens
-1 => Event::Refresh,

View File

@ -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);
});

View File

@ -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;
}
}
}
}
});

View File

@ -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();
}
}
}

View File

@ -61,7 +61,10 @@ impl InputParser {
for _ in request_receiver {
let event: Result<TEvent, ::std::io::Error> =
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();
}
}
}

View File

@ -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<Interruption> {
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)
}
}