mod attrs;
mod draw;
pub(super) mod filter;
pub(super) mod fit;
mod input;
pub(super) mod kind;
mod kinds;
mod nav;
mod row;
mod shown;
pub(super) mod tree;
use std::cell::{Cell, RefCell};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::rc::Rc;
use super::Screen;
use draw::Listing;
use filter::Filter;
use kind::Kind;
#[derive(Debug, Default)]
pub(super) struct FileList {
pub(super) closed: bool,
pub(super) filter: Filter,
filter_from: Option<super::Focus>,
shown: Vec<String>,
shown_set: HashSet<String>,
shown_totals: (u32, u32),
kinds: Vec<Kind>,
attributes: Option<(u64, std::sync::mpsc::Receiver<HashMap<String, bool>>)>,
index: HashMap<String, Vec<usize>>,
order: Vec<usize>,
collapsed: BTreeSet<String>,
pub(super) cursor: Option<String>,
scroll: usize,
scrolled_to: Option<String>,
pub(super) current: Option<String>,
chosen_width: Option<u16>,
pub(super) drawn_width: u16,
pub(super) clamped: bool,
pub(super) no_room: bool,
pending: Option<String>,
version: u64,
rows: RefCell<Option<(Built, Rc<Listing>)>>,
shown_version: u64,
shown_width: Cell<Option<(u64, u64, u16)>>,
}
#[derive(Debug)]
struct Built {
version: u64,
filter: Filter,
collapsed: BTreeSet<String>,
}
impl FileList {
pub(super) fn chosen_width(&self) -> Option<u16> {
self.chosen_width
}
pub(super) fn set_width(&mut self, width: Option<u16>) {
self.chosen_width = width;
self.closed = false;
}
pub(super) fn shown(&self) -> &[String] {
&self.shown
}
pub(super) fn is_shown(&self, path: &str) -> bool {
self.shown_set.contains(path)
}
pub(super) fn shown_totals(&self) -> (u32, u32) {
self.shown_totals
}
pub(super) fn viewed_changed(&mut self) {
self.version += 1;
}
pub(super) fn drawn(&mut self, width: u16) {
self.drawn_width = width;
self.clamped = width > 0 && self.chosen_width.is_some_and(|chosen| chosen > width);
}
#[cfg(test)]
pub(super) fn attributes_read(&self) -> bool {
self.attributes.is_none()
}
#[cfg(test)]
pub(super) fn kind_of(&self, path: &str) -> Option<Kind> {
self.index.get(path).and_then(|v| v.first()).and_then(|&i| self.kinds.get(i)).copied()
}
pub(super) fn retarget(&mut self) {
self.pending = self.current.clone().filter(|p| self.shown_set.contains(p));
}
}
impl Screen {
pub(super) fn files_wanted(&self) -> bool {
!self.files.closed
&& (self.capture.files.len() > 1
|| self.focus == super::Focus::Files
|| self.files.filter.is_active())
}
pub(super) fn files_heading(&self, listed: usize) -> String {
let total = self.capture.files.len();
if listed == total {
format!("Files \u{b7} {total}")
} else {
format!("Files \u{b7} {listed} of {total}")
}
}
}