mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix dummy & blt backends
This commit is contained in:
parent
2610b697a8
commit
af4e55ed18
@ -28,6 +28,9 @@ enum ColorRole {
|
||||
pub struct Backend {
|
||||
buttons_pressed: HashSet<MouseButton>,
|
||||
mouse_position: Vec2,
|
||||
|
||||
inner_sender: Sender<Option<Event>>,
|
||||
inner_receiver: Receiver<Option<Event>>,
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
@ -45,9 +48,13 @@ impl Backend {
|
||||
},
|
||||
]);
|
||||
|
||||
let (inner_sender, inner_receiver) = crossbeam_channel::bounded(1);
|
||||
|
||||
let c = Backend {
|
||||
buttons_pressed: HashSet::new(),
|
||||
mouse_position: Vec2::zero(),
|
||||
inner_sender,
|
||||
inner_receiver,
|
||||
};
|
||||
|
||||
Box::new(c)
|
||||
@ -307,10 +314,23 @@ impl backend::Backend for Backend {
|
||||
terminal::print_xy(pos.x as i32, pos.y as i32, text);
|
||||
}
|
||||
|
||||
fn prepare_input(
|
||||
&mut self, event_sink: &Sender<Option<Event>>,
|
||||
input_request: backend::InputRequest,
|
||||
fn start_input_thread(
|
||||
&mut self, event_sink: Sender<Option<Event>>,
|
||||
input_request: Receiver<backend::InputRequest>,
|
||||
) {
|
||||
let receiver = self.inner_receiver.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
for _ in input_requests {
|
||||
match receiver.recv() {
|
||||
None => return,
|
||||
Some(event) => event_sink.send(event),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn prepare_input(&mut self, input_request: backend::InputRequest) {
|
||||
match input_request {
|
||||
backend::InputRequest::Peek => event_sink.send(self.parse_next()),
|
||||
backend::InputRequest::Block => {
|
||||
@ -323,7 +343,7 @@ impl backend::Backend for Backend {
|
||||
return;
|
||||
}
|
||||
}
|
||||
event_sink.send(Some(Event::Refresh));
|
||||
self.inner_sender.send(Some(Event::Refresh));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,28 @@
|
||||
//! Dummy backend
|
||||
use std::thread;
|
||||
|
||||
use crossbeam_channel::{self, Receiver, Sender};
|
||||
|
||||
use backend;
|
||||
use event;
|
||||
use event::Event;
|
||||
use theme;
|
||||
use vec::Vec2;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
|
||||
pub struct Backend;
|
||||
pub struct Backend {
|
||||
inner_sender: Sender<Option<Event>>,
|
||||
inner_receiver: Receiver<Option<Event>>,
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
pub fn init() -> Box<backend::Backend>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Box::new(Backend)
|
||||
let (inner_sender, inner_receiver) = crossbeam_channel::bounded(1);
|
||||
Box::new(Backend {
|
||||
inner_sender,
|
||||
inner_receiver,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +39,24 @@ impl backend::Backend for Backend {
|
||||
(1, 1).into()
|
||||
}
|
||||
|
||||
fn prepare_input(
|
||||
&mut self, event_sink: &Sender<Option<event::Event>>,
|
||||
_input_request: backend::InputRequest,
|
||||
fn prepare_input(&mut self, _input_request: backend::InputRequest) {
|
||||
self.inner_sender.send(Some(Event::Exit));
|
||||
}
|
||||
|
||||
fn start_input_thread(
|
||||
&mut self, event_sink: Sender<Option<Event>>,
|
||||
input_requests: Receiver<backend::InputRequest>,
|
||||
) {
|
||||
event_sink.send(Some(event::Event::Exit))
|
||||
let receiver = self.inner_receiver.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
for _ in input_requests {
|
||||
match receiver.recv() {
|
||||
None => return,
|
||||
Some(event) => event_sink.send(event),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn print_at(&self, _: Vec2, _: &str) {}
|
||||
|
@ -57,13 +57,9 @@ pub trait Backend {
|
||||
///
|
||||
/// This is only required for non-thread-safe backends like BearLibTerminal
|
||||
/// where we cannot collect input in a separate thread.
|
||||
fn prepare_input(
|
||||
&mut self, event_sink: &Sender<Option<Event>>,
|
||||
input_request: InputRequest,
|
||||
) {
|
||||
fn prepare_input(&mut self, input_request: InputRequest) {
|
||||
// Dummy implementation for most backends.
|
||||
// Little trick to avoid unused variables.
|
||||
let _ = event_sink;
|
||||
let _ = input_request;
|
||||
}
|
||||
|
||||
|
@ -605,8 +605,7 @@ impl Cursive {
|
||||
}
|
||||
|
||||
self.input_trigger.send(backend::InputRequest::Peek);
|
||||
self.backend
|
||||
.prepare_input(&self.event_sink, backend::InputRequest::Peek);
|
||||
self.backend.prepare_input(backend::InputRequest::Peek);
|
||||
self.event_source.recv().unwrap().map(Interruption::Event)
|
||||
}
|
||||
|
||||
@ -616,8 +615,7 @@ impl Cursive {
|
||||
fn poll(&mut self) -> Option<Interruption> {
|
||||
if !self.expecting_event {
|
||||
self.input_trigger.send(backend::InputRequest::Block);
|
||||
self.backend
|
||||
.prepare_input(&self.event_sink, backend::InputRequest::Block);
|
||||
self.backend.prepare_input(backend::InputRequest::Block);
|
||||
self.expecting_event = true;
|
||||
}
|
||||
|
||||
@ -765,7 +763,6 @@ impl Cursive {
|
||||
fn handle_interruption(&mut self, interruption: Interruption) {
|
||||
match interruption {
|
||||
Interruption::Event(event) => {
|
||||
// eprintln!("{:?}, {:?}", event, self.screen_size());
|
||||
if event == Event::Exit {
|
||||
self.quit();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user