mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-01-14 20:46:14 +00:00
feat: improve help page layout and organization
This commit is contained in:
parent
e4fcc70c30
commit
59f86c31e5
123
src/ui/help.rs
123
src/ui/help.rs
@ -4,79 +4,76 @@ use ratatui::{
|
|||||||
widgets::{Block, BorderType, Borders, Cell, Clear, Row, Table},
|
widgets::{Block, BorderType, Borders, Cell, Clear, Row, Table},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::to_color;
|
|
||||||
|
|
||||||
pub fn render_help(frame: &mut Frame, app: &App) {
|
pub fn render_help(frame: &mut Frame, app: &App) {
|
||||||
let block = Block::default()
|
let kb = &app.config.keybinds;
|
||||||
.title("Help")
|
let key_style = Style::default().fg(Color::Yellow).bold();
|
||||||
.title_alignment(Alignment::Center)
|
let select_key = display_key(&kb.select);
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded);
|
|
||||||
|
|
||||||
let keybinds = app.config.keybinds.clone();
|
|
||||||
|
|
||||||
let rows = vec![
|
let rows = vec![
|
||||||
Row::new(vec![
|
section_row("── Navigation ──"),
|
||||||
Cell::from(keybinds.toggle_help),
|
key_row(&kb.prev_torrent, "Move up", key_style),
|
||||||
Cell::from("Show help"),
|
key_row(&kb.next_torrent, "Move down", key_style),
|
||||||
]),
|
key_row(&kb.prev_tab, "Previous tab", key_style),
|
||||||
Row::new(vec![Cell::from(keybinds.quit), Cell::from("Quit")]),
|
key_row(&kb.next_tab, "Next tab", key_style),
|
||||||
Row::new(vec![Cell::from(keybinds.prev_tab), Cell::from("Left")]),
|
key_row(&kb.switch_tab_1, "All torrents", key_style),
|
||||||
Row::new(vec![Cell::from(keybinds.next_tab), Cell::from("Right")]),
|
key_row(&kb.switch_tab_2, "Active torrents", key_style),
|
||||||
Row::new(vec![Cell::from(keybinds.next_torrent), Cell::from("Down")]),
|
key_row(&kb.switch_tab_3, "Downloading", key_style),
|
||||||
Row::new(vec![Cell::from(keybinds.prev_torrent), Cell::from("Up")]),
|
Row::default(),
|
||||||
Row::new(vec![
|
section_row("── Actions ──"),
|
||||||
Cell::from(keybinds.switch_tab_1),
|
key_row(&kb.toggle_torrent, "Start/stop torrent", key_style),
|
||||||
Cell::from("Switch to All tab"),
|
key_row(&kb.toggle_all, "Start/stop all", key_style),
|
||||||
]),
|
key_row(&select_key, "Multi-select", key_style),
|
||||||
Row::new(vec![
|
key_row(&kb.move_torrent, "Move torrent", key_style),
|
||||||
Cell::from(keybinds.switch_tab_2),
|
key_row(&kb.rename_torrent, "Rename torrent", key_style),
|
||||||
Cell::from("Switch to Active tab"),
|
key_row(&kb.delete, "Remove torrent", key_style),
|
||||||
]),
|
key_row(&kb.delete_force, "Delete with data", key_style),
|
||||||
Row::new(vec![
|
Row::default(),
|
||||||
Cell::from(keybinds.switch_tab_3),
|
section_row("── General ──"),
|
||||||
Cell::from("Switch to Downloading tab"),
|
key_row(&kb.toggle_help, "Toggle help", key_style),
|
||||||
]),
|
key_row(&kb.quit, "Quit", key_style),
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(keybinds.toggle_torrent),
|
|
||||||
Cell::from("Toggle torrent"),
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(keybinds.toggle_all),
|
|
||||||
Cell::from("Toggle all torrents"),
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(keybinds.delete),
|
|
||||||
Cell::from("Delete torrent"),
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(keybinds.delete_force),
|
|
||||||
Cell::from("Delete torrent and data"),
|
|
||||||
]),
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(keybinds.select),
|
|
||||||
Cell::from("Select torrent"),
|
|
||||||
]),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let table = Table::new(
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
rows,
|
let height = rows.len() as u16 + 4;
|
||||||
&[Constraint::Percentage(20), Constraint::Percentage(80)],
|
let width = 40;
|
||||||
)
|
|
||||||
.block(block)
|
let block = Block::default()
|
||||||
.style(Style::default().fg(to_color(&app.config.colors.info_foreground)));
|
.title(" Keybindings ")
|
||||||
|
.title_alignment(Alignment::Center)
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_type(BorderType::Rounded)
|
||||||
|
.border_style(Style::default().fg(Color::Cyan));
|
||||||
|
|
||||||
|
let table = Table::new(rows, [Constraint::Length(16), Constraint::Fill(1)]).block(block);
|
||||||
|
|
||||||
let area = frame.area();
|
let area = frame.area();
|
||||||
let height = 15; // Desired height for the help menu
|
|
||||||
let width = area.width; // Full width of the screen
|
|
||||||
|
|
||||||
let popup_area = Rect::new(
|
let popup_area = Rect::new(
|
||||||
area.x + (area.width - width) / 2, // Center horizontally
|
(area.width.saturating_sub(width)) / 2,
|
||||||
area.y + area.height - height, // Position at the very bottom
|
(area.height.saturating_sub(height)) / 2,
|
||||||
width,
|
width.min(area.width),
|
||||||
height,
|
height.min(area.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
frame.render_widget(Clear, popup_area);
|
frame.render_widget(Clear, popup_area);
|
||||||
frame.render_widget(table, popup_area);
|
frame.render_widget(table, popup_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn key_row<'a>(key: &'a str, desc: &'a str, key_style: Style) -> Row<'a> {
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(format!(" {key}")).style(key_style),
|
||||||
|
Cell::from(desc),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn section_row(title: &str) -> Row<'_> {
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(title).style(Style::default().fg(Color::DarkGray)),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_key(key: &str) -> String {
|
||||||
|
match key {
|
||||||
|
" " => "Space".to_string(),
|
||||||
|
k => k.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user