* work * resize working * move focus working * close pane working * selection and fullscreen working * pane title line * titles and conditional scroll title * whole tab resize working * plugin frames working * plugin splitting working * truncate pane frame titles * cleanup * panes always draw their own borders - also fix gap * toggle pane frames * move toggle to screen and fix some bugs * fix plugin frame toggle * fix terminal window resize * fix scrolling and fullscreen bugs * unit tests passing * e2e tests passing and new test for new frames added * refactor: TerminalPane and PluginPane * refactor: Tab * refactor: moar Tab * refactor: Boundaries * only render and calculate boundaries when there are no pane frames * refactor: Layout * fix(grid): properly resize when coming back from alternative viewport * style: remove commented code * style: fmt * style: fmt * style: fmt + clippy * docs(changelog): update change
63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
use pretty_bytes::converter as pb;
|
|
use std::{collections::HashMap, path::PathBuf};
|
|
|
|
#[derive(Default)]
|
|
pub struct State {
|
|
pub path: PathBuf,
|
|
pub files: Vec<FsEntry>,
|
|
pub cursor_hist: HashMap<PathBuf, (usize, usize)>,
|
|
pub hide_hidden_files: bool,
|
|
}
|
|
|
|
impl State {
|
|
pub fn selected_mut(&mut self) -> &mut usize {
|
|
&mut self.cursor_hist.entry(self.path.clone()).or_default().0
|
|
}
|
|
pub fn selected(&self) -> usize {
|
|
self.cursor_hist.get(&self.path).unwrap_or(&(0, 0)).0
|
|
}
|
|
pub fn scroll_mut(&mut self) -> &mut usize {
|
|
&mut self.cursor_hist.entry(self.path.clone()).or_default().1
|
|
}
|
|
pub fn scroll(&self) -> usize {
|
|
self.cursor_hist.get(&self.path).unwrap_or(&(0, 0)).1
|
|
}
|
|
pub fn toggle_hidden_files(&mut self) {
|
|
self.hide_hidden_files = !self.hide_hidden_files;
|
|
}
|
|
}
|
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
|
|
pub enum FsEntry {
|
|
Dir(PathBuf, usize),
|
|
File(PathBuf, u64),
|
|
}
|
|
|
|
impl FsEntry {
|
|
pub fn name(&self) -> String {
|
|
let path = match self {
|
|
FsEntry::Dir(p, _) => p,
|
|
FsEntry::File(p, _) => p,
|
|
};
|
|
path.file_name().unwrap().to_string_lossy().into_owned()
|
|
}
|
|
|
|
pub fn as_line(&self, width: usize) -> String {
|
|
let info = match self {
|
|
FsEntry::Dir(_, s) => s.to_string(),
|
|
FsEntry::File(_, s) => pb::convert(*s as f64),
|
|
};
|
|
let space = width.saturating_sub(info.len());
|
|
let name = self.name();
|
|
if space.saturating_sub(1) < name.len() {
|
|
[&name[..space.saturating_sub(2)], &info].join("~ ")
|
|
} else {
|
|
let padding = " ".repeat(space - name.len());
|
|
[name, padding, info].concat()
|
|
}
|
|
}
|
|
|
|
pub fn is_hidden_file(&self) -> bool {
|
|
self.name().starts_with('.')
|
|
}
|
|
}
|