command line warnings
This commit is contained in:
@@ -7,19 +7,27 @@ use ratatui::{
|
|||||||
};
|
};
|
||||||
use crate::client::colors::Theme;
|
use crate::client::colors::Theme;
|
||||||
|
|
||||||
pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme) {
|
pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme, message: &str) {
|
||||||
let prompt = if active {
|
let prompt = if active {
|
||||||
":"
|
":"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Combine the prompt, input, and message
|
||||||
|
let display_text = if message.is_empty() {
|
||||||
|
format!("{}{}", prompt, input)
|
||||||
|
} else {
|
||||||
|
format!("{}{} | {}", prompt, input, message)
|
||||||
|
};
|
||||||
|
|
||||||
let style = if active {
|
let style = if active {
|
||||||
Style::default().fg(theme.accent)
|
Style::default().fg(theme.accent)
|
||||||
} else {
|
} else {
|
||||||
Style::default().fg(theme.fg)
|
Style::default().fg(theme.fg)
|
||||||
};
|
};
|
||||||
|
|
||||||
let paragraph = Paragraph::new(format!("{}{}", prompt, input))
|
let paragraph = Paragraph::new(display_text)
|
||||||
.block(Block::default().style(Style::default().bg(theme.bg)))
|
.block(Block::default().style(Style::default().bg(theme.bg)))
|
||||||
.style(style);
|
.style(style);
|
||||||
|
|
||||||
|
|||||||
@@ -39,40 +39,36 @@ impl AppTerminal {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_command(&mut self, command_input: &str, is_saved: &mut bool) -> Result<bool, Box<dyn std::error::Error>> {
|
pub fn handle_command(&mut self, command_input: &str, is_saved: &mut bool) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
match command_input {
|
match command_input {
|
||||||
"w" => {
|
"w" => {
|
||||||
// Save the state
|
// Save the state
|
||||||
*is_saved = true;
|
*is_saved = true;
|
||||||
println!("State saved.");
|
Ok((false, "State saved.".to_string())) // Do not exit
|
||||||
Ok(false) // Do not exit
|
|
||||||
}
|
}
|
||||||
"q" => {
|
"q" => {
|
||||||
// Quit if saved
|
// Quit if saved
|
||||||
if *is_saved {
|
if *is_saved {
|
||||||
self.cleanup()?;
|
self.cleanup()?;
|
||||||
Ok(true) // Exit
|
Ok((true, "Exiting.".to_string())) // Exit
|
||||||
} else {
|
} else {
|
||||||
println!("No changes saved. Use :q! to force quit.");
|
Ok((false, "No changes saved. Use :q! to force quit.".to_string())) // Do not exit
|
||||||
Ok(false) // Do not exit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"q!" => {
|
"q!" => {
|
||||||
// Force quit without saving
|
// Force quit without saving
|
||||||
self.cleanup()?;
|
self.cleanup()?;
|
||||||
Ok(true) // Exit
|
Ok((true, "Force exiting without saving.".to_string())) // Exit
|
||||||
}
|
}
|
||||||
"wq" => {
|
"wq" => {
|
||||||
// Save and quit
|
// Save and quit
|
||||||
*is_saved = true;
|
*is_saved = true;
|
||||||
println!("State saved.");
|
|
||||||
self.cleanup()?;
|
self.cleanup()?;
|
||||||
Ok(true) // Exit
|
Ok((true, "State saved. Exiting.".to_string())) // Exit
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Handle other commands here
|
// Handle other commands here
|
||||||
println!("Command not recognized: {}", command_input);
|
Ok((false, format!("Command not recognized: {}", command_input))) // Do not exit
|
||||||
Ok(false) // Do not exit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Track whether the state has been saved
|
// Track whether the state has been saved
|
||||||
let mut is_saved = false;
|
let mut is_saved = false;
|
||||||
|
|
||||||
|
// Track the current message to display in the command line
|
||||||
|
let mut command_message = String::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
app_terminal.draw(|f| {
|
app_terminal.draw(|f| {
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
@@ -87,7 +90,7 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
render_status_line(f, root[1], ¤t_dir, &theme);
|
render_status_line(f, root[1], ¤t_dir, &theme);
|
||||||
|
|
||||||
// Command line
|
// Command line
|
||||||
render_command_line(f, root[2], &command_input, command_mode, &theme);
|
render_command_line(f, root[2], &command_input, command_mode, &theme, &command_message);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Event handling
|
// Event handling
|
||||||
@@ -96,7 +99,8 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
match key.code {
|
match key.code {
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
// Handle the command
|
// Handle the command
|
||||||
let should_exit = app_terminal.handle_command(&command_input, &mut is_saved)?;
|
let (should_exit, message) = app_terminal.handle_command(&command_input, &mut is_saved)?;
|
||||||
|
command_message = message; // Set the message to display
|
||||||
if should_exit {
|
if should_exit {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -110,6 +114,7 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
command_mode = false;
|
command_mode = false;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
|
command_message.clear(); // Clear the message when exiting command mode
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -118,6 +123,7 @@ pub fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
KeyCode::Char(':') => {
|
KeyCode::Char(':') => {
|
||||||
command_mode = true;
|
command_mode = true;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
|
command_message.clear(); // Clear the message when entering command mode
|
||||||
}
|
}
|
||||||
KeyCode::Tab => {
|
KeyCode::Tab => {
|
||||||
if key.modifiers.contains(KeyModifiers::SHIFT) {
|
if key.modifiers.contains(KeyModifiers::SHIFT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user