Implement item deletion

This commit is contained in:
Ian Keane 2025-11-16 12:25:22 -05:00
parent b1570a5e11
commit 401ee37b32
2 changed files with 126 additions and 16 deletions

View file

@ -23,12 +23,19 @@ pub fn render(frame: &mut Frame, app: &App) {
fn render_main(frame: &mut Frame, app: &App) {
// Calculate layout - accounting for bottom bar if needed
let show_bottom_bar = app.config.show_help_hint || app.config.show_command_hints;
let constraints = if show_bottom_bar {
let has_status = app.status_message.is_some();
let bottom_height = if show_bottom_bar {
if has_status { 2 } else { 1 }
} else {
if has_status { 1 } else { 0 }
};
let constraints = if bottom_height > 0 {
vec![
Constraint::Min(3), // At least 3 lines for each section
Constraint::Min(3),
Constraint::Min(3),
Constraint::Length(1), // Command bar
Constraint::Length(bottom_height), // Command bar + optional status
]
} else {
vec![
@ -43,7 +50,7 @@ fn render_main(frame: &mut Frame, app: &App) {
.constraints(constraints)
.split(frame.size());
let main_height = if show_bottom_bar {
let main_height = if bottom_height > 0 {
chunks[0].height + chunks[1].height + chunks[2].height
} else {
frame.size().height
@ -90,13 +97,8 @@ fn render_main(frame: &mut Frame, app: &App) {
);
// Render bottom bar if needed
if show_bottom_bar {
let bottom_area = Rect::new(
0,
frame.size().height - 1,
frame.size().width,
1,
);
if bottom_height > 0 {
let bottom_area = chunks[3];
render_bottom_bar(frame, bottom_area, app);
}
}
@ -173,10 +175,39 @@ fn render_new_entry(frame: &mut Frame, app: &App) {
}
fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
if app.config.show_command_hints {
// Split the area into status and command sections if needed
let chunks = if app.status_message.is_some() {
Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(1), // Status message
Constraint::Length(1), // Command bar
])
.split(area)
} else {
Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1)])
.split(area)
};
let mut command_line_idx = 0;
// Render status message if present
if let Some((ref message, _)) = app.status_message {
let text = Paragraph::new(message.as_str())
.style(Style::default().fg(Color::Yellow))
.alignment(Alignment::Center);
frame.render_widget(text, chunks[0]);
command_line_idx = 1;
}
// Render command hints
if app.config.show_command_hints && chunks.len() > command_line_idx {
let commands = vec![
("c", "config"),
("n", "new"),
("d", "delete"),
("q", "quit"),
];
@ -187,9 +218,14 @@ fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
let command_area = if app.config.show_help_hint {
// Leave space for help hint
Rect::new(area.x, area.y, area.width.saturating_sub(12), area.height)
Rect::new(
chunks[command_line_idx].x,
chunks[command_line_idx].y,
chunks[command_line_idx].width.saturating_sub(12),
1
)
} else {
area
chunks[command_line_idx]
};
let command_bar = Paragraph::new(command_text)
@ -199,14 +235,14 @@ fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
frame.render_widget(command_bar, command_area);
}
if app.config.show_help_hint {
if app.config.show_help_hint && chunks.len() > command_line_idx {
let help_hint = Paragraph::new("(?) for help")
.alignment(Alignment::Right)
.style(Style::default().fg(Color::DarkGray));
let help_area = Rect::new(
area.width.saturating_sub(12),
area.y,
chunks[command_line_idx].x + chunks[command_line_idx].width.saturating_sub(12),
chunks[command_line_idx].y,
12,
1,
);
@ -267,6 +303,7 @@ fn render_help(frame: &mut Frame, _app: &App) {
"j/k, arrows - Navigate",
"h/l, arrows - Switch panes",
"Enter - Start/stop timer",
"d - Delete task",
"Ctrl+e - Edit tasks config",
"c - Edit app config",
"n - New task",