aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/shared.rs
diff options
context:
space:
mode:
authorBrooks Rady <b.j.rady@gmail.com>2021-01-08 14:14:39 +0000
committerGitHub <noreply@github.com>2021-01-08 14:14:39 +0000
commit7efc435bdaf1aa29d72cda11105dd72c0fc1a891 (patch)
treeb617f2b607b072fcdd54f63987069d795f7aaf9e /src/utils/shared.rs
parentchore(cleanup): Clean up project root (#135) (diff)
parentDon't forget to tell split terminals that they have a new size! (diff)
downloadsl0ppij-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/utils/shared.rs')
-rw-r--r--src/utils/shared.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/shared.rs b/src/utils/shared.rs
new file mode 100644
index 00000000..1d8ca5c3
--- /dev/null
+++ b/src/utils/shared.rs
@@ -0,0 +1,19 @@
+use std::{iter, str::from_utf8};
+
+use strip_ansi_escapes::strip;
+
+pub fn ansi_len(s: &str) -> usize {
+ from_utf8(&strip(s.as_bytes()).unwrap())
+ .unwrap()
+ .chars()
+ .count()
+}
+
+pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String {
+ s.lines()
+ .map(|l| [l, &str::repeat(" ", columns - ansi_len(l))].concat())
+ .chain(iter::repeat(str::repeat(" ", columns)))
+ .take(rows)
+ .collect::<Vec<_>>()
+ .join("\n\r")
+}