-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bidirectional communication and streams for plugins (#11911)
- Loading branch information
Showing
47 changed files
with
8,010 additions
and
1,481 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::sync::{atomic::AtomicBool, Arc}; | ||
|
||
use nu_protocol::{ | ||
ast::Call, | ||
engine::{EngineState, Stack}, | ||
}; | ||
|
||
/// Object safe trait for abstracting operations required of the plugin context. | ||
pub(crate) trait PluginExecutionContext: Send + Sync { | ||
/// The interrupt signal, if present | ||
fn ctrlc(&self) -> Option<&Arc<AtomicBool>>; | ||
} | ||
|
||
/// The execution context of a plugin command. May be extended with more fields in the future. | ||
pub(crate) struct PluginExecutionCommandContext { | ||
ctrlc: Option<Arc<AtomicBool>>, | ||
} | ||
|
||
impl PluginExecutionCommandContext { | ||
pub fn new( | ||
engine_state: &EngineState, | ||
_stack: &Stack, | ||
_call: &Call, | ||
) -> PluginExecutionCommandContext { | ||
PluginExecutionCommandContext { | ||
ctrlc: engine_state.ctrlc.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl PluginExecutionContext for PluginExecutionCommandContext { | ||
fn ctrlc(&self) -> Option<&Arc<AtomicBool>> { | ||
self.ctrlc.as_ref() | ||
} | ||
} | ||
|
||
/// A bogus execution context for testing that doesn't really implement anything properly | ||
#[cfg(test)] | ||
pub(crate) struct PluginExecutionBogusContext; | ||
|
||
#[cfg(test)] | ||
impl PluginExecutionContext for PluginExecutionBogusContext { | ||
fn ctrlc(&self) -> Option<&Arc<AtomicBool>> { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.