aboutsummaryrefslogtreecommitdiffstats
path: root/src/errors.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/errors.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/errors.rs')
-rw-r--r--src/errors.rs34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/errors.rs b/src/errors.rs
index e4788e20..e53bbc30 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -1,17 +1,22 @@
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
-use crate::{AppInstruction, SenderWithContext, OPENCALLS};
-use backtrace::Backtrace;
+use crate::{AppInstruction, OPENCALLS};
+
use std::fmt::{Display, Error, Formatter};
-use std::panic::PanicInfo;
-use std::{process, thread};
const MAX_THREAD_CALL_STACK: usize = 6;
+#[cfg(not(test))]
+use crate::SenderWithContext;
+#[cfg(not(test))]
+use std::panic::PanicInfo;
+#[cfg(not(test))]
pub fn handle_panic(
info: &PanicInfo<'_>,
send_app_instructions: &SenderWithContext<AppInstruction>,
) {
+ use backtrace::Backtrace;
+ use std::{process, thread};
let backtrace = Backtrace::new();
let thread = thread::current();
let thread = thread.name().unwrap_or("unnamed");
@@ -84,6 +89,12 @@ impl ErrorContext {
}
}
+impl Default for ErrorContext {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Display for ErrorContext {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
writeln!(f, "Originating Thread(s):")?;
@@ -101,7 +112,7 @@ impl Display for ErrorContext {
pub enum ContextType {
Screen(ScreenContext),
Pty(PtyContext),
- #[cfg(feature = "wasm-wip")]
+
Plugin(PluginContext),
App(AppContext),
IPCServer,
@@ -117,7 +128,7 @@ impl Display for ContextType {
match *self {
ContextType::Screen(c) => write!(f, "{}screen_thread: {}{:?}", purple, green, c),
ContextType::Pty(c) => write!(f, "{}pty_thread: {}{:?}", purple, green, c),
- #[cfg(feature = "wasm-wip")]
+
ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c),
ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c),
ContextType::IPCServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green),
@@ -225,21 +236,24 @@ impl From<&PtyInstruction> for PtyContext {
}
// FIXME: This whole pattern *needs* a macro eventually, it's soul-crushing to write
-#[cfg(feature = "wasm-wip")]
+
use crate::wasm_vm::PluginInstruction;
-#[cfg(feature = "wasm-wip")]
+
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PluginContext {
Load,
+ Draw,
+ Input,
Unload,
Quit,
}
-#[cfg(feature = "wasm-wip")]
impl From<&PluginInstruction> for PluginContext {
fn from(plugin_instruction: &PluginInstruction) -> Self {
match *plugin_instruction {
- PluginInstruction::Load(_) => PluginContext::Load,
+ PluginInstruction::Load(..) => PluginContext::Load,
+ PluginInstruction::Draw(..) => PluginContext::Draw,
+ PluginInstruction::Input(..) => PluginContext::Input,
PluginInstruction::Unload(_) => PluginContext::Unload,
PluginInstruction::Quit => PluginContext::Quit,
}