diff options
Diffstat (limited to 'src/commands/quit.rs')
-rw-r--r-- | src/commands/quit.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/commands/quit.rs b/src/commands/quit.rs index 3173ca1..249db4b 100644 --- a/src/commands/quit.rs +++ b/src/commands/quit.rs @@ -1,5 +1,6 @@ use commands::{JoshutoCommand, JoshutoRunnable}; use context::JoshutoContext; +use ui; #[derive(Clone, Debug)] pub struct Quit; @@ -11,6 +12,18 @@ impl Quit { pub const fn command() -> &'static str { "quit" } + + pub fn quit(context: &mut JoshutoContext) { + if (!context.threads.is_empty()) { + ui::wprint_err( + &context.views.bot_win, + "Error: operations running in background, use force_quit to quit", + ); + ncurses::doupdate(); + return; + } + context.exit = true; + } } impl JoshutoCommand for Quit {} @@ -23,6 +36,36 @@ impl std::fmt::Display for Quit { impl JoshutoRunnable for Quit { fn execute(&self, context: &mut JoshutoContext) { + Self::quit(context); + } +} + +#[derive(Clone, Debug)] +pub struct ForceQuit; + +impl ForceQuit { + pub fn new() -> Self { + ForceQuit + } + pub const fn command() -> &'static str { + "force_quit" + } + + pub fn force_quit(context: &mut JoshutoContext) { context.exit = true; } } + +impl JoshutoCommand for ForceQuit {} + +impl std::fmt::Display for ForceQuit { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str(Self::command()) + } +} + +impl JoshutoRunnable for ForceQuit { + fn execute(&self, context: &mut JoshutoContext) { + Self::force_quit(context); + } +} |