diff options
| author | Brooks Rady <b.j.rady@gmail.com> | 2021-01-08 14:14:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-08 14:14:39 +0000 |
| commit | 7efc435bdaf1aa29d72cda11105dd72c0fc1a891 (patch) | |
| tree | b617f2b607b072fcdd54f63987069d795f7aaf9e /src/layout.rs | |
| parent | chore(cleanup): Clean up project root (#135) (diff) | |
| parent | Don't forget to tell split terminals that they have a new size! (diff) | |
| download | sl0ppij-7efc435bdaf1aa29d72cda11105dd72c0fc1a891.tar.gz sl0ppij-7efc435bdaf1aa29d72cda11105dd72c0fc1a891.tar.xz sl0ppij-7efc435bdaf1aa29d72cda11105dd72c0fc1a891.zip | |
feat(infra): initial plugin system
- Added the ability to load and keep track of several plugins at once
- Removed `wasm-wip` feature flag, enabling plugins in all builds
- `split_space` now returns a tuple with the `part_position_and_size` (as before) plus a cloned version of the part, so plugins and terminals can be distinguished by its users
- Added a `Draw` instruction for rendering plugins when asked to by Mosaic
- Added a new `PluginPane`, implementing `Pane` for plugins!
- Replaced RawFd as a pane-identifier with the `PaneId` enum in most places
- `change_size` -> `change_pos_and_size`, with the functionality updated to fit the new name
- `buffer_as_vte_output` -> `render`
- `pid()` on the `Pane` trait now returns a `PaneId`
- Changed lots of functions in `tab.rs` to be more pane oriented, renaming some to remove the `terminal` and switching to `PaneId`s
- splitting functions in `tab.rs` now correctly update the positions of returned fragments
- Used `PaneId`'s as a replacement for `PaneKind` in the tab `BTreeMap`
- Removed `get_rows` and `get_columns` from the `Pane` trait
- Layouts can now create plugin panes!
- Changed lots of the `active_terminal` stuff in `tab.rs` to work with all panes
- Changed the `Tab` `render` function, so that common requirements are moved there and out of the `Pane::render()` methods
- Added a `shared.rs` to `utils` with a couple of useful functions
- We can now accept input and pass it to plugins via serialised JSON
- Trigger a screen render after handling input meant for a plugin
- Allow plugins to be properly closed
- Allow plugin panes to be split (opening a new terminal)
- Allow plugin API functions to send messages on the PTY bus
- Added the API functionality needed for a plugin to open a file in a new pane
- No more compiler warnings!
- Fixed 53 clippy lints!
Diffstat (limited to 'src/layout.rs')
| -rw-r--r-- | src/layout.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/layout.rs b/src/layout.rs index 1e876532..c82fc404 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::{fs::File, io::prelude::*, path::PathBuf}; -use crate::terminal_pane::PositionAndSize; +use crate::panes::PositionAndSize; fn split_space_to_parts_vertically( space_to_split: &PositionAndSize, @@ -61,8 +61,11 @@ fn split_space_to_parts_horizontally( split_parts } -fn split_space(space_to_split: &PositionAndSize, layout: &Layout) -> Vec<PositionAndSize> { - let mut pane_positions: Vec<PositionAndSize> = vec![]; +fn split_space( + space_to_split: &PositionAndSize, + layout: &Layout, +) -> Vec<(Layout, PositionAndSize)> { + let mut pane_positions = Vec::new(); let percentages: Vec<u8> = layout .parts .iter() @@ -88,7 +91,7 @@ fn split_space(space_to_split: &PositionAndSize, layout: &Layout) -> Vec<Positio let mut part_positions = split_space(&part_position_and_size, part); pane_positions.append(&mut part_positions); } else { - pane_positions.push(*part_position_and_size); + pane_positions.push((part.clone(), *part_position_and_size)); } } pane_positions @@ -165,27 +168,22 @@ impl Layout { panic!("The total percent for each part should equal 100."); } } - pub fn total_panes(&self) -> usize { + + pub fn total_terminal_panes(&self) -> usize { let mut total_panes = 0; total_panes += self.parts.len(); for part in self.parts.iter() { - total_panes += part.total_panes(); + if part.plugin.is_none() { + total_panes += part.total_terminal_panes(); + } } total_panes } - // FIXME: I probably shouldn't exist, much less with PathBuf (use &Path) - #[cfg(feature = "wasm-wip")] - pub fn list_plugins(&self) -> Vec<&PathBuf> { - dbg!(&self); - let mut plugins: Vec<_> = self.parts.iter().flat_map(Layout::list_plugins).collect(); - if let Some(path) = &self.plugin { - plugins.push(path); - } - plugins - } - - pub fn position_panes_in_space(&self, space: &PositionAndSize) -> Vec<PositionAndSize> { + pub fn position_panes_in_space( + &self, + space: &PositionAndSize, + ) -> Vec<(Layout, PositionAndSize)> { split_space(space, &self) } } |
