use std::sync::{atomic::AtomicBool, Arc};
use nu_protocol::{
ast::Call,
engine::{EngineState, Stack},
};
pub(crate) trait PluginExecutionContext: Send + Sync {
fn ctrlc(&self) -> Option<&Arc<AtomicBool>>;
}
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()
}
}
#[cfg(test)]
pub(crate) struct PluginExecutionBogusContext;
#[cfg(test)]
impl PluginExecutionContext for PluginExecutionBogusContext {
fn ctrlc(&self) -> Option<&Arc<AtomicBool>> {
None
}
}