feat: add status bar with keybind hints and torrent count

This commit is contained in:
Kristofers Solo 2026-01-01 04:20:55 +02:00
parent 8ed46b1285
commit 35e6e420ea
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
2 changed files with 65 additions and 1 deletions

View File

@ -1,5 +1,6 @@
mod help;
mod input;
mod status;
mod table;
use crate::{
@ -27,7 +28,11 @@ pub fn render(app: &mut App, frame: &mut Frame) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
.constraints([
Constraint::Length(3),
Constraint::Min(0),
Constraint::Length(3),
])
.split(size);
let titles = app
@ -54,6 +59,8 @@ pub fn render(app: &mut App, frame: &mut Frame) {
frame.render_stateful_widget(table, chunks[1], &mut app.state);
status::render(frame, app, chunks[2]);
if app.show_help {
render_help(frame, app);
}

57
src/ui/status.rs Normal file
View File

@ -0,0 +1,57 @@
use crate::app::{App, InputMode};
use ratatui::{
prelude::*,
text::Span,
widgets::{Block, BorderType, Borders, Paragraph},
};
pub fn render(frame: &mut Frame, app: &App, area: Rect) {
let total = app.torrents.len();
let selected_count = app.torrents.selected.len();
let left = if selected_count > 0 {
format!(" {selected_count}/{total} selected")
} else {
format!(" {total} torrents")
};
let mode_text = match app.input_mode {
InputMode::Move => Some("MOVE"),
InputMode::Rename => Some("RENAME"),
InputMode::ConfirmDelete(_) => Some("DELETE"),
InputMode::None => None,
};
let keybinds = match app.input_mode {
InputMode::None => "q Quit │ ? Help │ ↑↓ Navigate │ Space Select │ Enter Toggle",
InputMode::Move | InputMode::Rename => "Enter Submit │ Esc Cancel │ Tab Complete",
InputMode::ConfirmDelete(_) => "y Confirm │ n Cancel",
};
let right = format!("{keybinds} ");
let available_width = area.width.saturating_sub(2) as usize;
let left_len = left.chars().count();
let right_len = right.chars().count();
let content = if left_len + right_len < available_width {
let padding = available_width.saturating_sub(left_len + right_len);
format!("{left}{}{right}", " ".repeat(padding))
} else {
right
};
let mut block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded);
if let Some(mode) = mode_text {
block = block
.title(format!(" {mode} "))
.title_style(Style::default().fg(Color::Yellow).bold());
}
let paragraph = Paragraph::new(Span::raw(content)).block(block);
frame.render_widget(paragraph, area);
}