summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlali <luteranlajos@protonmail.ch>2024-02-20 21:44:51 +0100
committerGitHub <noreply@github.com>2024-02-20 15:44:51 -0500
commitd0c251e2389d06823dfb1c589fa25f508c8467ab (patch)
treed98351cedfacdc08818e469c721a35af70347fd6
parent8d334cbe73ade11a0b48eea41971ab24644d43ab (diff)
fix selection style when lscolors enabled (#496)
* fix: selection style when lscolors enabled Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch> * make it readable Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch> * use unwrap_or_else() instead Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch> * fix some clippy warnings Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch> * Revert "fix some clippy warnings" This reverts commit 1521b462c90b52dd9e7ebd50b27b99bcefb9be99. * add ls_colors option to default config Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch> --------- Signed-off-by: Luterán Lajos <luteranlajos@protonmail.ch>
-rw-r--r--config/theme.toml5
-rw-r--r--src/util/style.rs101
2 files changed, 65 insertions, 41 deletions
diff --git a/config/theme.toml b/config/theme.toml
index 5d11e39..55379f5 100644
--- a/config/theme.toml
+++ b/config/theme.toml
@@ -1,4 +1,9 @@
##########################################
+## General
+##########################################
+lscolors_enabled = false
+
+##########################################
## Tabs
##########################################
diff --git a/src/util/style.rs b/src/util/style.rs
index 47ea9fd..ffe703c 100644
--- a/src/util/style.rs
+++ b/src/util/style.rs
@@ -26,48 +26,73 @@ impl PathStyleIfSome for Style {
}
pub fn entry_style(entry: &JoshutoDirEntry) -> Style {
- match &THEME_T.lscolors {
- Some(lscolors) => entry_lscolors_style(lscolors, entry),
- None => entry_theme_style(entry),
- }
-}
-
-fn entry_theme_style(entry: &JoshutoDirEntry) -> Style {
let metadata = &entry.metadata;
- let filetype = &metadata.file_type();
- let linktype = &metadata.link_type();
+ let filetype = metadata.file_type();
+ let linktype = metadata.link_type();
if entry.is_visual_mode_selected() {
- Style::default()
- .fg(THEME_T.visual_mode_selection.fg)
- .bg(THEME_T.visual_mode_selection.bg)
- .add_modifier(THEME_T.visual_mode_selection.modifier)
- } else if entry.is_permanent_selected() {
- Style::default()
- .fg(THEME_T.selection.fg)
- .bg(THEME_T.selection.bg)
- .add_modifier(THEME_T.selection.modifier)
- } else {
- match linktype {
- LinkType::Symlink { valid: true, .. } => Style::default()
- .fg(THEME_T.link.fg)
- .bg(THEME_T.link.bg)
- .add_modifier(THEME_T.link.modifier),
- LinkType::Symlink { valid: false, .. } => Style::default()
- .fg(THEME_T.link_invalid.fg)
- .bg(THEME_T.link_invalid.bg)
- .add_modifier(THEME_T.link_invalid.modifier),
- LinkType::Normal => match filetype {
- FileType::Directory => Style::default()
- .fg(THEME_T.directory.fg)
- .bg(THEME_T.directory.bg)
- .add_modifier(THEME_T.directory.modifier),
- FileType::File => file_style(entry),
- },
+ return visual_mode_selected_style();
+ }
+ if entry.is_permanent_selected() {
+ return permanent_selected_style();
+ }
+
+ match &THEME_T.lscolors {
+ Some(lscolors) => {
+ let path = entry.file_path();
+ lscolors_style(lscolors, path)
+ .unwrap_or_else(|| default_style(entry, linktype, filetype))
}
+ None => default_style(entry, linktype, filetype),
+ }
+}
+
+fn default_style(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),
+ },
}
}
+fn visual_mode_selected_style() -> Style {
+ Style::default()
+ .fg(THEME_T.visual_mode_selection.fg)
+ .bg(THEME_T.visual_mode_selection.bg)
+ .add_modifier(THEME_T.visual_mode_selection.modifier)
+}
+
+fn permanent_selected_style() -> Style {
+ Style::default()
+ .fg(THEME_T.selection.fg)
+ .bg(THEME_T.selection.bg)
+ .add_modifier(THEME_T.selection.modifier)
+}
+
+fn symlink_valid_style() -> Style {
+ Style::default()
+ .fg(THEME_T.link.fg)
+ .bg(THEME_T.link.bg)
+ .add_modifier(THEME_T.link.modifier)
+}
+
+fn symlink_invalid_style() -> Style {
+ Style::default()
+ .fg(THEME_T.link_invalid.fg)
+ .bg(THEME_T.link_invalid.bg)
+ .add_modifier(THEME_T.link_invalid.modifier)
+}
+
+fn directory_style() -> Style {
+ Style::default()
+ .fg(THEME_T.directory.fg)
+ .bg(THEME_T.directory.bg)
+ .add_modifier(THEME_T.directory.modifier)
+}
+
fn file_style(entry: &JoshutoDirEntry) -> Style {
let regular_style = Style::default()
.fg(THEME_T.regular.fg)
@@ -95,12 +120,6 @@ fn file_style(entry: &JoshutoDirEntry) -> Style {
}
}
-fn entry_lscolors_style(lscolors: &LsColors, entry: &JoshutoDirEntry) -> Style {
- let path = &entry.file_path();
- let default = Style::default();
- lscolors_style(lscolors, path).unwrap_or(default)
-}
-
fn lscolors_style(lscolors: &LsColors, path: &Path) -> Option<Style> {
let nu_ansi_term_style = lscolors.style_for_path(path)?.to_nu_ansi_term_style();
// Paths that are not valid UTF-8 are not styled by LS_COLORS.