diff options
| author | Brooks Rady <b.j.rady@gmail.com> | 2021-03-26 13:20:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-26 13:20:06 +0000 |
| commit | d818661c727a59312e1a43432e84fbeec79fc145 (patch) | |
| tree | e8ab04124ee7f5c87cd88be63c1867c7d9b2289c /src/common/screen.rs | |
| parent | fix(render): various rendering issues (#238) (diff) | |
| parent | Fix some overzealous format!() removals and a stray comment (diff) | |
| download | sl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.tar.gz sl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.tar.xz sl0ppij-d818661c727a59312e1a43432e84fbeec79fc145.zip | |
feat(plugin): refactored to a new and more general plugin API
- Changed `init()` to `load()`
- Deduplicated structs that are in both `zellij` and `zellij-tile`
- WASM thread now keeps a mapping of plugins and event subscriptions
- Added host-functions for subscribing and unsubscribing from events
- Introduced the `update(event)` callback into the API (which is called to handle plugin events)
- Made mode changes send an event to the WASM thread
- Removed the `AppInstruction::Get/SetState` calls (and any global state)
- Removed the `get_help()` host function
- Added an event system for key-presses
- Added an event for updating tabs
- Ported support for renaming tabs
- Removed every plugin callback other than `load()`, `update(event)`, and `draw(rows, cols)`
- Removed every WASM thread event other than Load, Draw, Update, Unload, and Quit
- Calls render after a plugin is updated
- Switched back to upstream `termion`
- Loads of lint fixing
- Shrunk and simplified the code!
Diffstat (limited to 'src/common/screen.rs')
| -rw-r--r-- | src/common/screen.rs | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/common/screen.rs b/src/common/screen.rs index bb77ab85..5208834a 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -5,14 +5,16 @@ use std::os::unix::io::RawFd; use std::str; use std::sync::mpsc::Receiver; -use super::{input::handler::InputMode, AppInstruction, SenderWithContext}; +use super::{AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; -use crate::tab::{Tab, TabData}; +use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; +use zellij_tile::data::{Event, InputMode, TabInfo}; + /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] pub enum ScreenInstruction { @@ -72,7 +74,6 @@ pub struct Screen { active_tab_index: Option<usize>, /// The [`OsApi`] this [`Screen`] uses. os_api: Box<dyn OsApi>, - tabname_buf: String, input_mode: InputMode, } @@ -98,7 +99,6 @@ impl Screen { active_tab_index: None, tabs: BTreeMap::new(), os_api, - tabname_buf: String::new(), input_mode, } } @@ -174,15 +174,12 @@ impl Screen { pub fn go_to_tab(&mut self, mut tab_index: usize) { tab_index -= 1; let active_tab = self.get_active_tab().unwrap(); - match self.tabs.values().find(|t| t.position == tab_index) { - Some(t) => { - if t.index != active_tab.index { - self.active_tab_index = Some(t.index); - self.update_tabs(); - self.render(); - } + if let Some(t) = self.tabs.values().find(|t| t.position == tab_index) { + if t.index != active_tab.index { + self.active_tab_index = Some(t.index); + self.update_tabs(); + self.render(); } - None => {} } } @@ -276,38 +273,33 @@ impl Screen { let mut tab_data = vec![]; let active_tab_index = self.active_tab_index.unwrap(); for tab in self.tabs.values() { - tab_data.push(TabData { + tab_data.push(TabInfo { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, }); } self.send_plugin_instructions - .send(PluginInstruction::UpdateTabs(tab_data)) + .send(PluginInstruction::Update(None, Event::TabUpdate(tab_data))) .unwrap(); } pub fn update_active_tab_name(&mut self, buf: Vec<u8>) { let s = str::from_utf8(&buf).unwrap(); + let active_tab = self.get_active_tab_mut().unwrap(); match s { "\0" => { - self.tabname_buf = String::new(); - } - "\n" => { - let new_name = self.tabname_buf.clone(); - let active_tab = self.get_active_tab_mut().unwrap(); - active_tab.name = new_name; - self.update_tabs(); - self.render(); + active_tab.name = String::new(); } "\u{007F}" | "\u{0008}" => { //delete and backspace keys - self.tabname_buf.pop(); + active_tab.name.pop(); } c => { - self.tabname_buf.push_str(c); + active_tab.name.push_str(c); } } + self.update_tabs(); } pub fn change_input_mode(&mut self, input_mode: InputMode) { self.input_mode = input_mode; |
