Converted tab updates to the new generic update() function
This commit is contained in:
parent
0371c111b7
commit
84a5cf95d1
8 changed files with 12 additions and 40 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,7 +524,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, 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<dyn OsApi>, 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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String>, u32, usize, usize), // String buffer, plugin id, rows, cols
|
||||
Input(PluginInputType, Vec<u8>), // plugin id, input bytes
|
||||
Unload(u32),
|
||||
UpdateTabs(Vec<TabInfo>), // num tabs, active tab
|
||||
Quit,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub enum Key {
|
|||
#[strum_discriminants(name(EventType))]
|
||||
pub enum Event {
|
||||
ModeUpdate(ModeInfo),
|
||||
TabUpdate(TabInfo),
|
||||
TabUpdate(Vec<TabInfo>),
|
||||
KeyPress(Key),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -36,10 +36,6 @@ pub fn set_selectable(selectable: bool) {
|
|||
unsafe { host_set_selectable(selectable) };
|
||||
}
|
||||
|
||||
pub fn get_tabs() -> Vec<TabInfo> {
|
||||
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<T: DeserializeOwned>() -> Option<T> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue