diff options
author | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-23 19:52:59 +0000 |
---|---|---|
committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-23 19:52:59 +0000 |
commit | ac55e590475fb68f29071fc06ded8f6d6bf5db22 (patch) | |
tree | 5cd73705a58232f10e9dd0943f2f503517356227 /zellij-tile/src | |
parent | 9bc7a268ce18b8e1f8d60f476903a6832f946de6 (diff) |
Initial implementation of the update callback + upstream termion
Diffstat (limited to 'zellij-tile/src')
-rw-r--r-- | zellij-tile/src/data.rs | 2 | ||||
-rw-r--r-- | zellij-tile/src/lib.rs | 10 | ||||
-rw-r--r-- | zellij-tile/src/shim.rs | 4 |
3 files changed, 14 insertions, 2 deletions
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 2a03b94c7..abca9994e 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -23,7 +23,7 @@ pub enum Key { Esc, } -#[derive(Debug, EnumDiscriminants, ToString, Serialize, Deserialize)] +#[derive(Debug, Clone, EnumDiscriminants, ToString, Serialize, Deserialize)] #[strum_discriminants(derive(Hash, Serialize, Deserialize))] #[strum_discriminants(name(EventType))] pub enum Event { diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 6adc9f6dc..eb1b08fb7 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -7,6 +7,7 @@ use data::*; #[allow(unused_variables)] pub trait ZellijTile { fn load(&mut self) {} + fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} // FIXME: Everything below this line should be purged fn handle_key(&mut self, key: Key) {} @@ -29,6 +30,15 @@ macro_rules! register_tile { } #[no_mangle] + pub fn update() { + STATE.with(|state| { + state + .borrow_mut() + .update($crate::shim::deserialize_from_stdin().unwrap()); + }); + } + + #[no_mangle] pub fn render(rows: i32, cols: i32) { STATE.with(|state| { state.borrow_mut().render(rows as usize, cols as usize); diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index 3681e9ba5..e0e654909 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -45,7 +45,9 @@ pub fn get_tabs() -> Vec<TabInfo> { deserialize_from_stdin().unwrap_or_default() } -fn deserialize_from_stdin<T: DeserializeOwned>() -> Option<T> { +#[doc(hidden)] +// FIXME: Make this just return T and do a .unwrap() at the end; also naming? +pub fn deserialize_from_stdin<T: DeserializeOwned>() -> Option<T> { let mut json = String::new(); io::stdin().read_line(&mut json).unwrap(); serde_json::from_str(&json).ok() |