mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-01-14 20:46:14 +00:00
feat: add status bar with keybind hints and torrent count
This commit is contained in:
parent
8ed46b1285
commit
35e6e420ea
@ -1,5 +1,6 @@
|
|||||||
mod help;
|
mod help;
|
||||||
mod input;
|
mod input;
|
||||||
|
mod status;
|
||||||
mod table;
|
mod table;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -27,7 +28,11 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
|||||||
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
|
.constraints([
|
||||||
|
Constraint::Length(3),
|
||||||
|
Constraint::Min(0),
|
||||||
|
Constraint::Length(3),
|
||||||
|
])
|
||||||
.split(size);
|
.split(size);
|
||||||
|
|
||||||
let titles = app
|
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);
|
frame.render_stateful_widget(table, chunks[1], &mut app.state);
|
||||||
|
|
||||||
|
status::render(frame, app, chunks[2]);
|
||||||
|
|
||||||
if app.show_help {
|
if app.show_help {
|
||||||
render_help(frame, app);
|
render_help(frame, app);
|
||||||
}
|
}
|
||||||
|
|||||||
57
src/ui/status.rs
Normal file
57
src/ui/status.rs
Normal 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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user