diff options
Diffstat (limited to 'src/repl')
| -rw-r--r-- | src/repl/abort.rs | 55 | ||||
| -rw-r--r-- | src/repl/highlighter.rs | 6 | ||||
| -rw-r--r-- | src/repl/mod.rs | 12 | ||||
| -rw-r--r-- | src/repl/prompt.rs | 6 |
4 files changed, 11 insertions, 68 deletions
diff --git a/src/repl/abort.rs b/src/repl/abort.rs deleted file mode 100644 index af58b35..0000000 --- a/src/repl/abort.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, -}; - -pub type AbortSignal = Arc<AbortSignalInner>; - -pub struct AbortSignalInner { - ctrlc: AtomicBool, - ctrld: AtomicBool, -} - -pub fn create_abort_signal() -> AbortSignal { - AbortSignalInner::new() -} - -impl AbortSignalInner { - pub fn new() -> AbortSignal { - Arc::new(Self { - ctrlc: AtomicBool::new(false), - ctrld: AtomicBool::new(false), - }) - } - - pub fn aborted(&self) -> bool { - if self.aborted_ctrlc() { - return true; - } - if self.aborted_ctrld() { - return true; - } - false - } - - pub fn aborted_ctrlc(&self) -> bool { - self.ctrlc.load(Ordering::SeqCst) - } - - pub fn aborted_ctrld(&self) -> bool { - self.ctrld.load(Ordering::SeqCst) - } - - pub fn reset(&self) { - self.ctrlc.store(false, Ordering::SeqCst); - self.ctrld.store(false, Ordering::SeqCst); - } - - pub fn set_ctrlc(&self) { - self.ctrlc.store(true, Ordering::SeqCst); - } - - pub fn set_ctrld(&self) { - self.ctrld.store(true, Ordering::SeqCst); - } -} diff --git a/src/repl/highlighter.rs b/src/repl/highlighter.rs index cca6297..37df659 100644 --- a/src/repl/highlighter.rs +++ b/src/repl/highlighter.rs @@ -1,15 +1,15 @@ -use crate::config::SharedConfig; +use crate::config::GlobalConfig; use nu_ansi_term::{Color, Style}; use reedline::{Highlighter, StyledText}; pub struct ReplHighlighter { external_commands: Vec<String>, - config: SharedConfig, + config: GlobalConfig, } impl ReplHighlighter { - pub fn new(external_commands: Vec<String>, config: SharedConfig) -> Self { + pub fn new(external_commands: Vec<String>, config: GlobalConfig) -> Self { Self { external_commands, config, diff --git a/src/repl/mod.rs b/src/repl/mod.rs index c9c3c73..c19058b 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -1,17 +1,15 @@ -mod abort; mod highlighter; mod prompt; mod validator; -pub use self::abort::{create_abort_signal, AbortSignal}; - use self::highlighter::ReplHighlighter; use self::prompt::ReplPrompt; use self::validator::ReplValidator; use crate::client::init_client; -use crate::config::SharedConfig; +use crate::config::GlobalConfig; use crate::render::{render_error, render_stream}; +use crate::utils::{create_abort_signal, AbortSignal}; use anyhow::{bail, Context, Result}; use arboard::Clipboard; @@ -52,7 +50,7 @@ lazy_static! { } pub struct Repl { - config: SharedConfig, + config: GlobalConfig, editor: Reedline, prompt: ReplPrompt, abort: AbortSignal, @@ -60,7 +58,7 @@ pub struct Repl { } impl Repl { - pub fn init(config: SharedConfig) -> Result<Self> { + pub fn init(config: GlobalConfig) -> Result<Self> { let commands: Vec<String> = REPL_COMMANDS .into_iter() .map(|(v, _)| v.to_string()) @@ -283,7 +281,7 @@ Type ".help" for more information. ) } - fn create_completer(config: &SharedConfig, commands: &[String]) -> DefaultCompleter { + fn create_completer(config: &GlobalConfig, commands: &[String]) -> DefaultCompleter { let mut completion = commands.to_vec(); completion.extend(config.read().repl_completions()); let mut completer = diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs index 7007b53..b4c9099 100644 --- a/src/repl/prompt.rs +++ b/src/repl/prompt.rs @@ -1,4 +1,4 @@ -use crate::config::SharedConfig; +use crate::config::GlobalConfig; use crossterm::style::Color; use reedline::{Prompt, PromptHistorySearch, PromptHistorySearchStatus}; @@ -11,11 +11,11 @@ const PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5); #[derive(Clone)] pub struct ReplPrompt { - config: SharedConfig, + config: GlobalConfig, } impl ReplPrompt { - pub fn new(config: SharedConfig) -> Self { + pub fn new(config: GlobalConfig) -> Self { Self { config } } } |
