use std::fs;
use std::io;
use std::path::PathBuf;
mod config;
mod rows;
mod session;
#[cfg(test)]
mod tests;
pub use self::{config::*, rows::*, session::*};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum SortKey {
Name,
Extension,
Size,
Modified,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum IconStyle {
NerdFont,
NerdFontMono,
Plain,
}
impl IconStyle {
pub fn is_wide(self) -> bool {
self == IconStyle::NerdFont
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Theme {
Synthwave,
Outrun,
Vaporwave,
HighContrast,
Dracula,
Monokai,
Nord,
GruvboxDark,
SolarizedDark,
TokyoNight,
CatppuccinMocha,
SolarizedLight,
GruvboxLight,
CatppuccinLatte,
GithubLight,
}
impl Theme {
pub const ALL: [Theme; 15] = [
Theme::Synthwave,
Theme::Outrun,
Theme::Vaporwave,
Theme::HighContrast,
Theme::Dracula,
Theme::Monokai,
Theme::Nord,
Theme::GruvboxDark,
Theme::SolarizedDark,
Theme::TokyoNight,
Theme::CatppuccinMocha,
Theme::SolarizedLight,
Theme::GruvboxLight,
Theme::CatppuccinLatte,
Theme::GithubLight,
];
pub fn label(self) -> &'static str {
match self {
Theme::Synthwave => "Synthwave",
Theme::Outrun => "Outrun",
Theme::Vaporwave => "Vaporwave",
Theme::HighContrast => "High contrast",
Theme::Dracula => "Dracula",
Theme::Monokai => "Monokai",
Theme::Nord => "Nord",
Theme::GruvboxDark => "Gruvbox Dark",
Theme::SolarizedDark => "Solarized Dark",
Theme::TokyoNight => "Tokyo Night",
Theme::CatppuccinMocha => "Catppuccin Mocha",
Theme::SolarizedLight => "Solarized Light",
Theme::GruvboxLight => "Gruvbox Light",
Theme::CatppuccinLatte => "Catppuccin Latte",
Theme::GithubLight => "GitHub Light",
}
}
fn key(self) -> &'static str {
match self {
Theme::Synthwave => "synthwave",
Theme::Outrun => "outrun",
Theme::Vaporwave => "vaporwave",
Theme::HighContrast => "high-contrast",
Theme::Dracula => "dracula",
Theme::Monokai => "monokai",
Theme::Nord => "nord",
Theme::GruvboxDark => "gruvbox-dark",
Theme::SolarizedDark => "solarized-dark",
Theme::TokyoNight => "tokyo-night",
Theme::CatppuccinMocha => "catppuccin-mocha",
Theme::SolarizedLight => "solarized-light",
Theme::GruvboxLight => "gruvbox-light",
Theme::CatppuccinLatte => "catppuccin-latte",
Theme::GithubLight => "github-light",
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DateFormat {
Short,
Iso,
Relative,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum SizeUnits {
Binary,
Decimal,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum OnExisting {
Ask,
Overwrite,
Refuse,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Clock {
Hours24,
Hours12,
Off,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum CursorShape {
Bar,
Block,
Underline,
Classic,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ScrollBarStyle {
Heavy,
Double,
Dashed,
Block,
Shade,
Ascii,
}
impl ScrollBarStyle {
pub const ALL: [ScrollBarStyle; 6] = [ScrollBarStyle::Heavy, ScrollBarStyle::Double, ScrollBarStyle::Dashed, ScrollBarStyle::Block, ScrollBarStyle::Shade, ScrollBarStyle::Ascii];
pub fn thumbs(self) -> (&'static str, &'static str) {
match self {
ScrollBarStyle::Heavy => ("┃", "━"),
ScrollBarStyle::Double => ("║", "═"),
ScrollBarStyle::Dashed => ("╏", "╍"),
ScrollBarStyle::Block => ("█", "█"),
ScrollBarStyle::Shade => ("▓", "▓"),
ScrollBarStyle::Ascii => ("#", "#"),
}
}
pub fn label(self) -> &'static str {
match self {
ScrollBarStyle::Heavy => "Heavy",
ScrollBarStyle::Double => "Double",
ScrollBarStyle::Dashed => "Dashed",
ScrollBarStyle::Block => "Block",
ScrollBarStyle::Shade => "Shade",
ScrollBarStyle::Ascii => "ASCII",
}
}
pub(super) fn key(self) -> &'static str {
match self {
ScrollBarStyle::Heavy => "heavy",
ScrollBarStyle::Double => "double",
ScrollBarStyle::Dashed => "dashed",
ScrollBarStyle::Block => "block",
ScrollBarStyle::Shade => "shade",
ScrollBarStyle::Ascii => "ascii",
}
}
}
const TAB_WIDTHS: [usize; 3] = [2, 4, 8];
const HIGHLIGHT_LIMITS_KIB: [u64; 4] = [0, 256, 512, 2048];
const LARGE_FILE_LIMITS_MIB: [u64; 3] = [16, 64, 256];
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Options {
pub show_hidden: bool,
pub sort_key: SortKey,
pub sort_descending: bool,
pub dirs_first: bool,
pub case_sensitive: bool,
pub column_ext: bool,
pub column_size: bool,
pub column_modified: bool,
pub column_attributes: bool,
pub date_format: DateFormat,
pub size_units: SizeUnits,
pub confirm_delete: bool,
pub delete_to_trash: bool,
pub confirm_copy_move: bool,
pub on_existing: OnExisting,
pub terminal: String,
pub editor: String,
pub remember_dirs: bool,
pub preview_on_start: bool,
pub theme: Theme,
pub theme_background: bool,
pub icon_style: IconStyle,
pub clock: Clock,
pub cursor: CursorShape,
pub cursor_blink: bool,
pub tab_width: usize,
pub line_numbers: bool,
pub scroll_bar: ScrollBarStyle,
pub highlight_limit_kib: u64,
pub large_file_mib: u64,
pub image_fill: bool,
pub image_backgrounds: bool,
pub image_prefetch: bool,
}
impl Default for Options {
fn default() -> Self {
Self {
show_hidden: true,
sort_key: SortKey::Extension,
sort_descending: false,
dirs_first: true,
case_sensitive: false,
column_ext: true,
column_size: true,
column_modified: true,
column_attributes: true,
date_format: DateFormat::Short,
size_units: SizeUnits::Binary,
confirm_delete: true,
delete_to_trash: true,
confirm_copy_move: true,
on_existing: OnExisting::Ask,
terminal: String::new(),
editor: String::new(),
remember_dirs: false,
preview_on_start: false,
theme: Theme::Synthwave,
theme_background: true,
icon_style: IconStyle::NerdFont,
clock: Clock::Hours24,
cursor: CursorShape::Bar,
cursor_blink: true,
tab_width: 4,
line_numbers: true,
scroll_bar: ScrollBarStyle::Heavy,
highlight_limit_kib: 512,
large_file_mib: 64,
image_fill: false,
image_backgrounds: true,
image_prefetch: true,
}
}
}
impl Options {
pub fn highlight_limit_bytes(&self) -> u64 {
self.highlight_limit_kib * 1024
}
pub fn large_file_bytes(&self) -> u64 {
self.large_file_mib * 1024 * 1024
}
}