2019-03-30 16:48:36 +00:00
|
|
|
use std::borrow::Cow;
|
2020-06-06 21:33:20 +00:00
|
|
|
use std::fmt::{self, Debug, Formatter};
|
|
|
|
use std::sync::Arc;
|
2016-09-01 17:24:20 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
use crate::term::{ClipboardType, SizeInfo};
|
2016-12-11 06:44:13 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
#[derive(Clone)]
|
2019-10-05 00:29:26 +00:00
|
|
|
pub enum Event {
|
|
|
|
MouseCursorDirty,
|
|
|
|
Title(String),
|
2020-07-11 17:03:09 +00:00
|
|
|
ResetTitle,
|
2020-06-06 21:33:20 +00:00
|
|
|
ClipboardStore(ClipboardType, String),
|
|
|
|
ClipboardLoad(ClipboardType, Arc<dyn Fn(&str) -> String + Sync + Send + 'static>),
|
2019-10-05 00:29:26 +00:00
|
|
|
Wakeup,
|
2020-07-10 19:32:44 +00:00
|
|
|
Bell,
|
2019-10-05 00:29:26 +00:00
|
|
|
Exit,
|
|
|
|
}
|
2016-09-01 17:24:20 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
impl Debug for Event {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Event::MouseCursorDirty => write!(f, "MouseCursorDirty"),
|
|
|
|
Event::Title(title) => write!(f, "Title({})", title),
|
2020-07-11 17:03:09 +00:00
|
|
|
Event::ResetTitle => write!(f, "ResetTitle"),
|
2020-06-06 21:33:20 +00:00
|
|
|
Event::ClipboardStore(ty, text) => write!(f, "ClipboardStore({:?}, {})", ty, text),
|
|
|
|
Event::ClipboardLoad(ty, _) => write!(f, "ClipboardLoad({:?})", ty),
|
|
|
|
Event::Wakeup => write!(f, "Wakeup"),
|
2020-07-10 19:32:44 +00:00
|
|
|
Event::Bell => write!(f, "Bell"),
|
2020-06-06 21:33:20 +00:00
|
|
|
Event::Exit => write!(f, "Exit"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Byte sequences are sent to a `Notify` in response to some events.
|
2016-12-26 23:33:27 +00:00
|
|
|
pub trait Notify {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Notify that an escape sequence should be written to the PTY.
|
2016-12-26 23:33:27 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// TODO this needs to be able to error somehow.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn notify<B: Into<Cow<'static, [u8]>>>(&mut self, _: B);
|
2016-12-26 23:33:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Types that are interested in when the display is resized.
|
2019-10-05 00:29:26 +00:00
|
|
|
pub trait OnResize {
|
|
|
|
fn on_resize(&mut self, size: &SizeInfo);
|
2017-02-02 06:13:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Event Loop for notifying the renderer about terminal events.
|
2019-10-05 00:29:26 +00:00
|
|
|
pub trait EventListener {
|
|
|
|
fn send_event(&self, event: Event);
|
2016-09-01 17:24:20 +00:00
|
|
|
}
|