Skip to content

Commit

Permalink
rename case_sensitive_ext to case_insensitive_ext
Browse files Browse the repository at this point in the history
 - make case_insensitive_ext option work with themes as well
  • Loading branch information
kamiyaa committed Mar 11, 2024
1 parent 93d2a18 commit b6db70f
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 267 deletions.
504 changes: 278 additions & 226 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/joshuto.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use_trash = true
watch_files = true
xdg_open = false
xdg_open_fork = false
case_sensitive_ext = false
case_insensitive_ext = false

custom_commands = []

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/joshuto.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ xdg_open_fork = false

# If true, all file extensions checks will be case sensitive.
# Applies to `[extension]` in `mimetype.toml` and `[ext]` in `theme.toml` and `icons.toml`
case_sensitive_ext = false
case_insensitive_ext = false

# Use system trash can instead of permanently removing files
use_trash = true
Expand Down
1 change: 0 additions & 1 deletion src/commands/change_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub fn change_directory(context: &mut AppContext, mut path: &path::Path) -> AppR
cd(new_cwd.as_path(), context)?;
let dirlists = generate_entries_to_root(
new_cwd.as_path(),
context.config_ref(),
context.tab_context_ref().curr_tab_ref().history_ref(),
context.ui_context_ref(),
context.config_ref().display_options_ref(),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn _get_options<'a>(path: &path::Path, config: &AppConfig) -> Vec<&'a ProgramEnt
.extension()
.and_then(|ext| ext.to_str())
.and_then(|ext| {
if config.case_sensitive_ext {
if config.case_insensitive_ext {
MIMETYPE_T.app_list_for_ext(ext)
} else {
MIMETYPE_T.app_list_for_ext(&ext.to_lowercase())
Expand Down
2 changes: 0 additions & 2 deletions src/commands/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use uuid::Uuid;
pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
let mut dirlists = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
let config = context.config_ref();
let display_options = context.config_ref().display_options_ref();
let tab_options = context.tab_context_ref().curr_tab_ref().option_ref();
let history = curr_tab.history_ref();
Expand Down Expand Up @@ -50,7 +49,6 @@ pub fn soft_reload_curr_tab(context: &mut AppContext) -> std::io::Result<()> {
pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
let mut dirlists = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
let config = context.config_ref();
let display_options = context.config_ref().display_options_ref();
let tab_options = context.tab_context_ref().curr_tab_ref().option_ref();
let history = curr_tab.history_ref();
Expand Down
1 change: 0 additions & 1 deletion src/commands/tab_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ pub fn new_tab(context: &mut AppContext, mode: &NewTabMode) -> AppResult {
.clone();
let dirlists = generate_entries_to_root(
new_tab_path.as_path(),
context.config_ref(),
&new_tab_history,
context.ui_context_ref(),
context.config_ref().display_options_ref(),
Expand Down
4 changes: 2 additions & 2 deletions src/config/clean/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct AppConfig {
pub use_trash: bool,
pub xdg_open: bool,
pub xdg_open_fork: bool,
pub case_sensitive_ext: bool,
pub case_insensitive_ext: bool,
pub watch_files: bool,
pub custom_commands: Vec<CustomCommand>,
pub focus_on_create: bool,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl From<AppConfigRaw> for AppConfig {
use_trash: raw.use_trash,
xdg_open: raw.xdg_open,
xdg_open_fork: raw.xdg_open_fork,
case_sensitive_ext: raw.case_sensitive_ext,
case_insensitive_ext: raw.case_insensitive_ext,
watch_files: raw.watch_files,
cmd_aliases: raw.cmd_aliases,
focus_on_create: raw.focus_on_create,
Expand Down
2 changes: 1 addition & 1 deletion src/config/raw/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct AppConfigRaw {
#[serde(default)]
pub xdg_open: bool,
#[serde(default)]
pub case_sensitive_ext: bool,
pub case_insensitive_ext: bool,
#[serde(default)]
pub xdg_open_fork: bool,
#[serde(default = "default_true")]
Expand Down
1 change: 0 additions & 1 deletion src/fs/dirlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{io, path};

use crate::config::clean::app::display::tab::TabDisplayOption;
use crate::config::clean::app::display::DisplayOption;
use crate::config::clean::app::AppConfig;
use crate::context::UiContext;
use crate::fs::{JoshutoDirEntry, JoshutoMetadata};
use crate::history::read_directory;
Expand Down
8 changes: 1 addition & 7 deletions src/fs/entry.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use std::{fs, io, path};

use crate::{
config::clean::app::{display::DisplayOption, AppConfig},
fs::{FileType, JoshutoMetadata},
};

#[cfg(feature = "devicons")]
use crate::ICONS_T;
use crate::{config::clean::app::display::DisplayOption, fs::JoshutoMetadata};

#[derive(Clone, Debug)]
pub struct JoshutoDirEntry {
Expand Down
2 changes: 0 additions & 2 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use walkdir::WalkDir;
use crate::config::clean::app::display::dirlist::DirListDisplayOptions;
use crate::config::clean::app::display::tab::TabDisplayOption;
use crate::config::clean::app::display::DisplayOption;
use crate::config::clean::app::AppConfig;
use crate::context::UiContext;
use crate::fs::{JoshutoDirEntry, JoshutoDirList, JoshutoMetadata};

Expand Down Expand Up @@ -227,7 +226,6 @@ where

pub fn generate_entries_to_root(
path: &Path,
config: &AppConfig,
history: &JoshutoHistory,
ui_context: &UiContext,
display_options: &DisplayOption,
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ lazy_static! {
static ref ICONS_T: Icons = Icons::get_config();

static ref HOME_DIR: Option<PathBuf> = dirs_next::home_dir();
static ref USERNAME: String = whoami::username();
static ref HOSTNAME: String = whoami::hostname();

static ref USERNAME: String = whoami::fallible::realname().unwrap_or("No Username".to_string());
static ref HOSTNAME: String = whoami::fallible::hostname().unwrap_or("No Hostname".to_string());

static ref TIMEZONE_STR: String = {
let offset = chrono::Local::now().offset().local_minus_utc() / 3600;
Expand Down
1 change: 0 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn run_loop(
.clone();
let dirlists = generate_entries_to_root(
curr_path.as_path(),
context.config_ref(),
&new_tab_history,
context.ui_context_ref(),
context.config_ref().display_options_ref(),
Expand Down
14 changes: 7 additions & 7 deletions src/ui/widgets/tui_dirlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ impl<'a> Widget for TuiDirList<'a> {
let ix = skip_dist + i;

let style = if !self.focused {
style::entry_style(entry)
style::entry_style(self.config, entry)
} else if ix == curr_index {
style::entry_style(entry).add_modifier(Modifier::REVERSED)
style::entry_style(self.config, entry).add_modifier(Modifier::REVERSED)
} else {
style::entry_style(entry)
style::entry_style(self.config, entry)
};

buf.set_string(x, y + i as u16, space_fill.as_str(), style);
Expand Down Expand Up @@ -89,7 +89,7 @@ fn print_entry(
#[cfg(feature = "devicons")]
let (label, label_width) = {
if config.display_options_ref().show_icons() {
let icon = get_entry_icon(&config, entry.file_name(), entry.ext(), &entry.metadata);
let icon = get_entry_icon(config, entry.file_name(), entry.ext(), &entry.metadata);
let label = format!("{icon} {name}");
let label_width = label.width();
(label, label_width)
Expand Down Expand Up @@ -135,10 +135,10 @@ pub fn get_entry_icon(
.map(|s| s.as_str())
.unwrap_or_else(|| {
ext.and_then(|ext| {
let ext: String = if config.case_sensitive_ext {
ext.to_owned()
} else {
let ext: String = if config.case_insensitive_ext {
ext.to_lowercase()
} else {
ext.to_owned()
};
ICONS_T.ext.get(&ext).map(|s| s.as_str())
})
Expand Down
8 changes: 4 additions & 4 deletions src/ui/widgets/tui_dirlist_detailed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
let ix = skip_dist + i;

let style = if !self.focused {
style::entry_style(entry)
style::entry_style(self.config, entry)
} else if ix == curr_index {
style::entry_style(entry).add_modifier(Modifier::REVERSED)
style::entry_style(self.config, entry).add_modifier(Modifier::REVERSED)
} else {
style::entry_style(entry)
style::entry_style(self.config, entry)
};

buf.set_string(x, y + i as u16, space_fill.as_str(), style);
Expand Down Expand Up @@ -156,7 +156,7 @@ fn print_entry(
#[cfg(feature = "devicons")]
let label = {
if config.display_options_ref().show_icons() {
let icon = get_entry_icon(&config, entry.file_name(), entry.ext(), &entry.metadata);
let icon = get_entry_icon(config, entry.file_name(), entry.ext(), &entry.metadata);
format!("{icon} {name}")
} else {
name.to_string()
Expand Down
26 changes: 19 additions & 7 deletions src/util/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use lscolors::LsColors;
use ratatui::style::Style;
use std::path::Path;

use crate::config::clean::app::AppConfig;
use crate::fs::{FileType, JoshutoDirEntry, LinkType};
use crate::util::unix;

Expand All @@ -25,7 +26,7 @@ impl PathStyleIfSome for Style {
}
}

pub fn entry_style(entry: &JoshutoDirEntry) -> Style {
pub fn entry_style(config: &AppConfig, entry: &JoshutoDirEntry) -> Style {
let metadata = &entry.metadata;
let filetype = metadata.file_type();
let linktype = metadata.link_type();
Expand All @@ -41,9 +42,9 @@ pub fn entry_style(entry: &JoshutoDirEntry) -> Style {
Some(lscolors) => {
let path = entry.file_path();
lscolors_style(lscolors, path)
.unwrap_or_else(|| default_style(entry, linktype, filetype))
.unwrap_or_else(|| default_style(config, entry, linktype, filetype))
}
None => default_style(entry, linktype, filetype),
None => default_style(config, entry, linktype, filetype),
}
}

Expand All @@ -63,13 +64,18 @@ pub fn entry_prefix(entry: &JoshutoDirEntry) -> (&str, usize) {
("", 0)
}

fn default_style(entry: &JoshutoDirEntry, linktype: &LinkType, filetype: &FileType) -> Style {
fn default_style(
config: &AppConfig,
entry: &JoshutoDirEntry,
linktype: &LinkType,
filetype: &FileType,
) -> Style {
match linktype {
LinkType::Symlink { valid: true, .. } => symlink_valid_style(),
LinkType::Symlink { valid: false, .. } => symlink_invalid_style(),
LinkType::Normal => match filetype {
FileType::Directory => directory_style(),
FileType::File => file_style(entry),
FileType::File => file_style(config, entry),
},
}
}
Expand Down Expand Up @@ -109,7 +115,7 @@ fn directory_style() -> Style {
.add_modifier(THEME_T.directory.modifier)
}

fn file_style(entry: &JoshutoDirEntry) -> Style {
fn file_style(config: &AppConfig, entry: &JoshutoDirEntry) -> Style {
let regular_style = Style::default()
.fg(THEME_T.regular.fg)
.bg(THEME_T.regular.bg)
Expand All @@ -123,7 +129,13 @@ fn file_style(entry: &JoshutoDirEntry) -> Style {
} else {
entry
.ext()
.and_then(|s| THEME_T.ext.get(s))
.and_then(|s| {
if config.case_insensitive_ext {
THEME_T.ext.get(&s.to_lowercase())
} else {
THEME_T.ext.get(s)
}
})
.map(|theme| {
Style::default()
.fg(theme.fg)
Expand Down

0 comments on commit b6db70f

Please sign in to comment.