wip
This commit is contained in:
parent
5b2fc70fee
commit
a0b0b7a7f8
|
@ -5,7 +5,7 @@ use std::{
|
|||
|
||||
use nu_plugin_engine::{GetPlugin, PluginInterface};
|
||||
use nu_protocol::{
|
||||
engine::{ctrlc, EngineState, Stack},
|
||||
engine::{EngineState, Stack},
|
||||
PluginGcConfig, PluginIdentity, PluginMetadata, RegisteredPlugin, ShellError,
|
||||
};
|
||||
|
||||
|
@ -52,10 +52,6 @@ impl RegisteredPlugin for FakePersistentPlugin {
|
|||
// We don't have a GC
|
||||
}
|
||||
|
||||
fn set_ctrlc_handler_guard(&self, _guard: ctrlc::Guard) {
|
||||
// We don't have a Ctrl-C handler
|
||||
}
|
||||
|
||||
fn stop(&self) -> Result<(), ShellError> {
|
||||
// We can't stop
|
||||
Ok(())
|
||||
|
|
|
@ -260,6 +260,16 @@ impl EngineState {
|
|||
if !delta.plugins.is_empty() {
|
||||
// Replace plugins that overlap in identity.
|
||||
for plugin in std::mem::take(&mut delta.plugins) {
|
||||
if let Some(handlers) = self.ctrlc_handlers.as_ref() {
|
||||
let guard = {
|
||||
let plugin = plugin.clone();
|
||||
handlers.register(Box::new(move || {
|
||||
let _ = plugin.ctrlc();
|
||||
}))?
|
||||
};
|
||||
plugin.set_ctrlc_handler_guard(guard);
|
||||
}
|
||||
|
||||
if let Some(existing) = self
|
||||
.plugins
|
||||
.iter_mut()
|
||||
|
|
|
@ -22,9 +22,6 @@ pub trait RegisteredPlugin: Send + Sync {
|
|||
/// Set garbage collection config for the plugin.
|
||||
fn set_gc_config(&self, gc_config: &PluginGcConfig);
|
||||
|
||||
/// Set a reference to the raii guard for the plugin's Ctrl-C handler.
|
||||
fn set_ctrlc_handler_guard(&self, guard: ctrlc::Guard);
|
||||
|
||||
/// Stop the plugin.
|
||||
fn stop(&self) -> Result<(), ShellError>;
|
||||
|
||||
|
@ -37,4 +34,12 @@ pub trait RegisteredPlugin: Send + Sync {
|
|||
/// This is necessary in order to allow `nu_plugin` to handle the implementation details of
|
||||
/// plugins.
|
||||
fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
|
||||
|
||||
/// Set a reference to the RAII guard for the plugin's Ctrl-C handler.
|
||||
fn set_ctrlc_handler_guard(&self, _guard: ctrlc::Guard) {}
|
||||
|
||||
/// Send a Ctrl-C signal to the plugin.
|
||||
fn ctrlc(&self) -> Result<(), ShellError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user