refactor(tui): one page window and one filter editor for every list

Four panes had grown the same dance around ratatui's table: clamp the
selection, take the visible page, hand the table a page-local state,
keep the page start. It is now page_window and render_page in a paging
module beside page_of, and the two popups page by the same count they
draw, tab bar or header included.

Five typed filters had grown the same key handling too. edit_filter now
takes a key for all of them, which also stops a control or alt chord
from typing its letter into a filter, stops Enter, which keeps a filter,
from resetting the view it is over, and lets the results and room-list
filters page like the others. Their titles and the typing shortcuts
come from one place as well.
This commit is contained in:
Michel de Graaf
2026-09-08 11:24:59 +02:00
parent 607532cc44
commit 0cacc8cc10
13 changed files with 293 additions and 299 deletions
+10 -20
View File
@@ -1,5 +1,5 @@
use super::MainTui;
use super::input::{jumped, list_jump};
use super::input::{FilterEdit, edit_filter, jumped, list_jump};
use crate::models::BrowseStatus;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::{thread, time::Duration};
@@ -27,7 +27,9 @@ impl MainTui {
self.state.show_browse = false;
return;
}
let jump = list_jump(key, self.popup_page());
// The tab bar takes a row once more than one user is open.
let chrome = u16::from(self.state.browse.tabs.len() > 1);
let jump = list_jump(key, self.popup_page(chrome));
// Control combinations are only ever jumps: ctrl-d pages, d downloads.
if jump.is_none() && key.modifiers.contains(KeyModifiers::CONTROL) {
return;
@@ -173,24 +175,12 @@ impl MainTui {
let Some(browse) = self.state.browse.active_tab_mut() else {
return false;
};
match key.code {
KeyCode::Esc => {
browse.filtering = false;
browse.set_filter(String::new());
}
KeyCode::Enter => browse.filtering = false,
KeyCode::Char(c) => {
let mut filter = browse.filter().to_string();
filter.push(c);
browse.set_filter(filter);
}
KeyCode::Backspace => {
let mut filter = browse.filter().to_string();
filter.pop();
browse.set_filter(filter);
}
_ => return false,
}
let mut filter = browse.filter().to_string();
let Some(edit) = edit_filter(&mut filter, key) else {
return false;
};
browse.filtering = edit == FilterEdit::Changed;
browse.set_filter(filter);
self.sync_browse_selection();
true
}