diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index a245dc1f..7f5e438d 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -51,8 +51,13 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(1); - self.mode = BarMode::Normal; - self.new_name = String::new(); + subscribe(&[EventType::TabUpdate]); + } + + fn update(&mut self, event: Event) { + if let Event::TabUpdate(tabs) = event { + self.tabs = tabs; + } } fn render(&mut self, _rows: usize, cols: usize) { @@ -84,10 +89,6 @@ impl ZellijTile for State { println!("{}\u{1b}[48;5;238m\u{1b}[0K", s); } - fn update_tabs(&mut self) { - self.tabs = get_tabs(); - } - fn handle_tab_rename_keypress(&mut self, key: Key) { self.mode = BarMode::Rename; match key { diff --git a/src/common/errors.rs b/src/common/errors.rs index 7b194f5d..83860a59 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -285,7 +285,6 @@ pub enum PluginContext { Input, Unload, Quit, - Tabs, } impl From<&PluginInstruction> for PluginContext { @@ -297,7 +296,6 @@ impl From<&PluginInstruction> for PluginContext { PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::Unload(_) => PluginContext::Unload, PluginInstruction::Quit => PluginContext::Quit, - PluginInstruction::UpdateTabs(..) => PluginContext::Tabs, } } } diff --git a/src/common/mod.rs b/src/common/mod.rs index f291eb19..15a28d96 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -524,7 +524,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let subs = plugin_env.subscriptions.lock().unwrap(); // FIXME: This is very janky... Maybe I should write my own macro for Event -> EventType? let event_type = EventType::from_str(&event.to_string()).unwrap(); - if pid.is_none() || pid == Some(i) && subs.contains(&event_type) { + if (pid.is_none() || pid == Some(i)) && subs.contains(&event_type) { let update = instance.exports.get_function("update").unwrap(); wasi_write_string( &plugin_env.wasi_env, @@ -546,20 +546,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { buf_tx.send(wasi_stdout(&plugin_env.wasi_env)).unwrap(); } - PluginInstruction::UpdateTabs(mut tabs) => { - for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&NaughtyEventType::Tab) { - continue; - } - let handler = instance.exports.get_function("update_tabs").unwrap(); - tabs.sort_by(|a, b| a.position.cmp(&b.position)); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&tabs).unwrap(), - ); - handler.call(&[]).unwrap(); - } - } // FIXME: Deduplicate this with the callback below! PluginInstruction::Input(input_type, input_bytes) => { let PluginInputType::Event(event) = input_type; diff --git a/src/common/screen.rs b/src/common/screen.rs index 89205f73..e902099c 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -13,7 +13,7 @@ use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; -use zellij_tile::data::{InputMode, TabInfo}; +use zellij_tile::data::{Event, InputMode, TabInfo}; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] @@ -282,7 +282,7 @@ impl Screen { }); } self.send_plugin_instructions - .send(PluginInstruction::UpdateTabs(tab_data)) + .send(PluginInstruction::Update(None, Event::TabUpdate(tab_data))) .unwrap(); } diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index d6334e56..249ad9ca 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -6,7 +6,7 @@ use std::{ }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use zellij_tile::data::{Event, EventType, TabInfo}; +use zellij_tile::data::{Event, EventType}; use super::{ pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, PaneId, SenderWithContext, @@ -29,7 +29,6 @@ pub enum PluginInstruction { Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols Input(PluginInputType, Vec), // plugin id, input bytes Unload(u32), - UpdateTabs(Vec), // num tabs, active tab Quit, } diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 67bf0d74..9576285a 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -28,7 +28,7 @@ pub enum Key { #[strum_discriminants(name(EventType))] pub enum Event { ModeUpdate(ModeInfo), - TabUpdate(TabInfo), + TabUpdate(Vec), KeyPress(Key), } diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 771edb2d..cff3624d 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -10,7 +10,6 @@ pub trait ZellijTile { fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} // FIXME: Everything below this line should be purged - fn update_tabs(&mut self) {} fn handle_tab_rename_keypress(&mut self, key: Key) {} } @@ -43,13 +42,6 @@ macro_rules! register_tile { }); } - #[no_mangle] - pub fn update_tabs() { - STATE.with(|state| { - state.borrow_mut().update_tabs(); - }) - } - #[no_mangle] pub fn handle_tab_rename_keypress() { STATE.with(|state| { diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index bbdf5fcc..1bb8ccab 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -36,10 +36,6 @@ pub fn set_selectable(selectable: bool) { unsafe { host_set_selectable(selectable) }; } -pub fn get_tabs() -> Vec { - deserialize_from_stdin().unwrap_or_default() -} - #[doc(hidden)] // FIXME: Make this just return T and do a .unwrap() at the end; also naming? pub fn deserialize_from_stdin() -> Option {