better working
This commit is contained in:
@@ -38,4 +38,42 @@ impl AppTerminal {
|
||||
execute!(self.terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_command(&mut self, command_input: &str, is_saved: &mut bool) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
match command_input {
|
||||
"w" => {
|
||||
// Save the state
|
||||
*is_saved = true;
|
||||
println!("State saved.");
|
||||
Ok(false) // Do not exit
|
||||
}
|
||||
"q" => {
|
||||
// Quit if saved
|
||||
if *is_saved {
|
||||
self.cleanup()?;
|
||||
Ok(true) // Exit
|
||||
} else {
|
||||
println!("No changes saved. Use :q! to force quit.");
|
||||
Ok(false) // Do not exit
|
||||
}
|
||||
}
|
||||
"q!" => {
|
||||
// Force quit without saving
|
||||
self.cleanup()?;
|
||||
Ok(true) // Exit
|
||||
}
|
||||
"wq" => {
|
||||
// Save and quit
|
||||
*is_saved = true;
|
||||
println!("State saved.");
|
||||
self.cleanup()?;
|
||||
Ok(true) // Exit
|
||||
}
|
||||
_ => {
|
||||
// Handle other commands here
|
||||
println!("Command not recognized: {}", command_input);
|
||||
Ok(false) // Do not exit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user