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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,37 +95,10 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if command_mode {
|
||||
match key.code {
|
||||
KeyCode::Enter => {
|
||||
match command_input.as_str() {
|
||||
"w" => {
|
||||
// Save the state
|
||||
is_saved = true;
|
||||
println!("State saved.");
|
||||
}
|
||||
"q" => {
|
||||
// Quit if saved
|
||||
if is_saved {
|
||||
app_terminal.cleanup()?;
|
||||
return Ok(());
|
||||
} else {
|
||||
println!("No changes saved. Use :q! to force quit.");
|
||||
}
|
||||
}
|
||||
"q!" => {
|
||||
// Force quit without saving
|
||||
app_terminal.cleanup()?;
|
||||
return Ok(());
|
||||
}
|
||||
"wq" => {
|
||||
// Save and quit
|
||||
is_saved = true;
|
||||
println!("State saved.");
|
||||
app_terminal.cleanup()?;
|
||||
return Ok(());
|
||||
}
|
||||
_ => {
|
||||
// Handle other commands here
|
||||
println!("Command not recognized: {}", command_input);
|
||||
}
|
||||
// Handle the command
|
||||
let should_exit = app_terminal.handle_command(&command_input, &mut is_saved)?;
|
||||
if should_exit {
|
||||
return Ok(());
|
||||
}
|
||||
command_mode = false;
|
||||
command_input.clear();
|
||||
|
||||
Reference in New Issue
Block a user