Revamp help management
This commit is contained in:
parent
1d1778037c
commit
56f9322e36
1 changed files with 14 additions and 102 deletions
116
src/ui.rs
116
src/ui.rs
|
|
@ -28,7 +28,7 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||||
|
|
||||||
fn render_main(frame: &mut Frame, app: &App) {
|
fn render_main(frame: &mut Frame, app: &App) {
|
||||||
// Calculate layout - accounting for bottom bar if needed
|
// Calculate layout - accounting for bottom bar if needed
|
||||||
let show_bottom_bar = app.config.show_help_hint || app.config.show_command_hints;
|
let show_bottom_bar = app.config.show_help_hint;
|
||||||
let has_status = app.status_message.is_some();
|
let has_status = app.status_message.is_some();
|
||||||
let bottom_height = if show_bottom_bar {
|
let bottom_height = if show_bottom_bar {
|
||||||
if has_status {
|
if has_status {
|
||||||
|
|
@ -170,86 +170,22 @@ fn render_new_entry(frame: &mut Frame, app: &App) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
|
fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
|
||||||
// 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
|
// Render status message if present
|
||||||
if let Some((ref message, _)) = app.status_message {
|
if let Some((ref message, _)) = app.status_message {
|
||||||
let text = Paragraph::new(message.as_str())
|
let text = Paragraph::new(message.as_str())
|
||||||
.style(Style::default().fg(Color::Yellow))
|
.style(Style::default().fg(Color::Yellow))
|
||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
frame.render_widget(text, chunks[0]);
|
frame.render_widget(text, area);
|
||||||
command_line_idx = 1;
|
} else if app.config.show_help_hint {
|
||||||
|
render_help_hint(frame, area);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Render command hints
|
fn render_help_hint(frame: &mut Frame, area: Rect) {
|
||||||
if app.config.show_command_hints && chunks.len() > command_line_idx {
|
let help_hint = Paragraph::new("(?) for help")
|
||||||
let commands = vec![
|
.alignment(Alignment::Right)
|
||||||
("c", "config"),
|
.style(Style::default().fg(Color::DarkGray));
|
||||||
("n", "new"),
|
frame.render_widget(help_hint, area);
|
||||||
("p", "project"),
|
|
||||||
("v", "log"),
|
|
||||||
("d", "delete"),
|
|
||||||
("q", "quit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let command_text = format!(
|
|
||||||
" {}",
|
|
||||||
commands
|
|
||||||
.iter()
|
|
||||||
.map(|(key, desc)| format!("{} ({})", key, desc))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(" · ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let command_area = if app.config.show_help_hint {
|
|
||||||
// Leave space for help hint
|
|
||||||
Rect::new(
|
|
||||||
chunks[command_line_idx].x,
|
|
||||||
chunks[command_line_idx].y,
|
|
||||||
chunks[command_line_idx].width.saturating_sub(12),
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
chunks[command_line_idx]
|
|
||||||
};
|
|
||||||
|
|
||||||
let command_bar = Paragraph::new(command_text)
|
|
||||||
.style(Style::default().fg(Color::White))
|
|
||||||
.alignment(Alignment::Left);
|
|
||||||
|
|
||||||
frame.render_widget(command_bar, command_area);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
|
||||||
chunks[command_line_idx].x + chunks[command_line_idx].width.saturating_sub(12),
|
|
||||||
chunks[command_line_idx].y,
|
|
||||||
12,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
|
|
||||||
frame.render_widget(help_hint, help_area);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_help_command_bar(frame: &mut Frame) {
|
fn render_help_command_bar(frame: &mut Frame) {
|
||||||
|
|
@ -559,34 +495,10 @@ fn render_log_view(frame: &mut Frame, app: &App) {
|
||||||
let list = List::new(items).block(block);
|
let list = List::new(items).block(block);
|
||||||
frame.render_widget(list, chunks[0]);
|
frame.render_widget(list, chunks[0]);
|
||||||
|
|
||||||
// Render command bar
|
// Render help hint at bottom if enabled
|
||||||
let commands = vec![
|
if app.config.show_help_hint {
|
||||||
("d", "day"),
|
render_help_hint(frame, chunks[1]);
|
||||||
("w", "week"),
|
}
|
||||||
("m", "month"),
|
|
||||||
("g", "group"),
|
|
||||||
("j/k", "select"),
|
|
||||||
("e", "edit"),
|
|
||||||
("x", "delete"),
|
|
||||||
("c", "copy"),
|
|
||||||
("?", "help"),
|
|
||||||
("q/ESC", "back"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let command_text = format!(
|
|
||||||
" {}",
|
|
||||||
commands
|
|
||||||
.iter()
|
|
||||||
.map(|(key, desc)| format!("{} ({})", key, desc))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(" · ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let command_bar = Paragraph::new(command_text)
|
|
||||||
.style(Style::default().fg(Color::White))
|
|
||||||
.alignment(Alignment::Left);
|
|
||||||
|
|
||||||
frame.render_widget(command_bar, chunks[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_log_view_help(frame: &mut Frame, _app: &App) {
|
fn render_log_view_help(frame: &mut Frame, _app: &App) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue