summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-30 20:00:48 +0100
committerqkzk <qu3nt1n@gmail.com>2023-10-30 20:03:44 +0100
commit3f2a118b19e421a040e3e5334796d48e6ee67731 (patch)
tree0e380018847e6176521cd95d27dad255b88042ce
parent48875f6d0c22da351a02a5daf538597da06ab6d5 (diff)
remove color configuration & caching. All colors are calculated every time
-rw-r--r--config_files/fm/config.yaml9
-rw-r--r--development.md3
-rw-r--r--readme.md8
-rw-r--r--src/color_cache.rs45
-rw-r--r--src/colors.rs18
-rw-r--r--src/config.rs87
-rw-r--r--src/event_dispatch.rs8
-rw-r--r--src/fileinfo.rs13
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs5
-rw-r--r--src/term_manager.rs12
11 files changed, 31 insertions, 179 deletions
diff --git a/config_files/fm/config.yaml b/config_files/fm/config.yaml
index 8095b10..b5719f8 100644
--- a/config_files/fm/config.yaml
+++ b/config_files/fm/config.yaml
@@ -1,14 +1,5 @@
# the terminal must be installed
terminal: st
-colors:
- # white, black, red, green, blue, yellow, cyan, magenta
- # light_white, light_black, light_red, light_green, light_blue, light_yellow, light_cyan, light_magenta
- block: yellow
- char: green
- directory: red
- fifo: blue
- socket: cyan
- symlink: magenta
# keybindings
keys:
'esc': ResetMode
diff --git a/development.md b/development.md
index dc087cd..ec29008 100644
--- a/development.md
+++ b/development.md
@@ -594,7 +594,8 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] add MTP mount points to shortcuts
- [x] list, mount, unmount mtp mount points
- [x] bulk, skim & removable are `None` until first use.
-- [ ] remove dependencies
+- [x] remove dependencies
+- [x] remove colors configuration. Calculate every color for every extension
- [ ] document filepicking (from my config etc.).
- [ ] avoid multiple refreshs if we edit files ourself
diff --git a/readme.md b/readme.md
index 974e060..b9e5fd9 100644
--- a/readme.md
+++ b/readme.md
@@ -289,7 +289,6 @@ Every configuration file is saved in `~/.config/fm/`
You can configure :
-- **Colors** for non standard file types (directory, socket, char device, block device)
- **Keybindings**. Some should be left as they are, but all keybindings can be configured.
use the provided config file as a default.
Multiple keys can be bound the the same action.
@@ -310,11 +309,13 @@ You can configure :
Open the menu with `S` and pick the desired one. It will only work with a TUI application like HTOP,
not a CLI application like bat.
+Before version 0.1.23, colors used to be configurable. Configuration wasn't a problem but passing it everywhere was a burden.
+
## External dependencies
Most of the openers and tui applications are configurable from config files. Some are hardcoded if their command is quite specific or if I couldn't find a workaround.
-- [lsblk](https://linux.die.net/man/8/lsblk): list encroytped devices
+- [lsblk](https://linux.die.net/man/8/lsblk): list encrytped devices
- [faillock](https://linux.die.net/man/8/faillock): reset failed sudo attempts
- [Cryptsetup](https://gitlab.com/cryptsetup/cryptsetup): decrypt & mount encrypted devices
- [Nitrogen](https://github.com/l3ib/nitrogen/): set up a wallpaper
@@ -323,9 +324,10 @@ Most of the openers and tui applications are configurable from config files. Som
- [Ueberzug](https://github.com/LalleSX/ueberzug) display images in your terminal. Used to preview images. This one may be tricky to install from source since the original maintener nuked his project. It's still available in many package managers.
- [isoinfo](https://command-not-found.com/isoinfo) allow the content preview of an iso file
- [jupyter](https://jupyter.org/) preview jupyter notebooks by converting them to markdown
-- [pandoc](https://pandoc.org) preview open documents by converting them to markdown with pandoc
+- [pandoc](https://pandoc.org) preview epub by converting them to markdown with pandoc
- [fontimage](https://fontforge.org/docs/fontutils/fontimage.html) preview fonts by creating a thumbnail
- [rsvg-convert](https://github.com/brion/librsvg) preview svg by creating a thumbnail
+- [libreoffice](https://www.libreoffice.org) preview open & MS-office documents
## Contribution
diff --git a/src/color_cache.rs b/src/color_cache.rs
deleted file mode 100644
index e8af4cd..0000000
--- a/src/color_cache.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-// use std::cell::RefCell;
-// use std::collections::HashMap;
-use std::hash::Hasher;
-
-use tuikit::attr::Color;
-
-/// Holds a map of extension name to color.
-/// Every extension is associated to a color which is only computed once
-/// per run. This trades a bit of memory for a bit of CPU.
-#[derive(Default, Clone, Debug)]
-pub struct ColorCache {
- // cache: RefCell<HashMap<String, Color>>,
-}
-
-// impl ColorCache {
-// /// Returns a color for any possible extension.
-// /// The color is cached within the struct, avoiding multiple calculations.
-// pub fn extension_color(&self, extension: &str) -> Color {
-// let mut cache = self.cache.borrow_mut();
-// if let Some(color) = cache.get(extension) {
-// color.to_owned()
-// } else {
-// let color = extension_color(extension);
-// cache.insert(extension.to_owned(), color);
-// color
-// }
-// }
-// }
-
-/// Picks a blueish/greenish color on color picker hexagon's perimeter.
-fn color(coords: usize) -> Color {
- (128..255)
- .map(|b| Color::Rgb(0, 255, b))
- .chain((128..255).map(|g| Color::Rgb(0, g, 255)))
- .chain((128..255).rev().map(|b| Color::Rgb(0, 255, b)))
- .chain((128..255).rev().map(|g| Color::Rgb(0, g, 255)))
- .nth(coords % 508)
- .unwrap()
-}
-
-pub fn extension_color(extension: &str) -> Color {
- let mut hasher = std::collections::hash_map::DefaultHasher::new();
- hasher.write(extension.as_bytes());
- color(hasher.finish() as usize)
-}
diff --git a/src/colors.rs b/src/colors.rs
new file mode 100644
index 0000000..f7d20ac
--- /dev/null
+++ b/src/colors.rs
@@ -0,0 +1,18 @@
+use std::hash::Hasher;
+
+use tuikit::attr::Color;
+
+/// Picks a blueish/greenish color on color picker hexagon's perimeter.
+fn color(hash: usize) -> Color {
+ (128..255)
+ .map(|b| Color::Rgb(0, 255, b))
+ .chain((128..255).map(|g| Color::Rgb(0, g, 255)))
+ .nth(hash % 254)
+ .unwrap()
+}
+
+pub fn extension_color(extension: &str) -> Color {
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ hasher.write(extension.as_bytes());
+ color(hasher.finish() as usize)
+}
diff --git a/src/config.rs b/src/config.rs
index 5a87c64..3909cb9 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -39,13 +39,6 @@ impl Settings {
}
}
-// macro_rules! update_attribute {
-// ($self_attr:expr, $yaml:ident, $key:expr) => {
-// if let Some(attr) = read_yaml_value($yaml, $key) {
-// $self_attr = attr;
-// }
-// };
-// }
/// Holds every configurable aspect of the application.
/// All attributes are hardcoded then updated from optional values
/// of the config file.
@@ -96,86 +89,6 @@ impl Config {
}
}
-// fn read_yaml_value(yaml: &serde_yaml::value::Value, key: &str) -> Option<String> {
-// yaml[key].as_str().map(|s| s.to_string())
-// }
-
-// /// Holds configurable colors for every kind of file.
-// /// "Normal" files are displayed with a different color by extension.
-// #[derive(Debug, Clone)]
-// pub struct Colors {
-// /// Color for `directory` files.
-// pub directory: String,
-// /// Color for `block` files.
-// pub block: String,
-// /// Color for `char` files.
-// pub char: String,
-// /// Color for `fifo` files.
-// pub fifo: String,
-// /// Color for `socket` files.
-// pub socket: String,
-// /// Color for `symlink` files.
-// pub symlink: String,
-// /// Color for broken `symlink` files.
-// pub broken: String,
-// // /// Colors for normal files, depending of extension
-// // pub color_cache: ColorCache,
-// }
-//
-// impl Colors {
-// fn update_from_config(&mut self, yaml: &serde_yaml::value::Value) {
-// update_attribute!(self.directory, yaml, "directory");
-// update_attribute!(self.block, yaml, "block");
-// update_attribute!(self.char, yaml, "char");
-// update_attribute!(self.fifo, yaml, "fifo");
-// update_attribute!(self.socket, yaml, "socket");
-// update_attribute!(self.symlink, yaml, "symlink");
-// update_attribute!(self.broken, yaml, "broken");
-// }
-//
-// fn new() -> Self {
-// Self {
-// directory: "red".to_owned(),
-// block: "yellow".to_owned(),
-// char: "green".to_owned(),
-// fifo: "blue".to_owned(),
-// socket: "cyan".to_owned(),
-// symlink: "magenta".to_owned(),
-// broken: "white".to_owned(),
-// // color_cache: ColorCache::default(),
-// }
-// }
-// }
-//
-// impl Default for Colors {
-// fn default() -> Self {
-// Self::new()
-// }
-// }
-//
-// /// Convert a string color into a `tuikit::Color` instance.
-// pub fn str_to_tuikit(color: &str) -> Color {
-// match color {
-// "white" => Color::WHITE,
-// "red" => Color::RED,
-// "green" => Color::GREEN,
-// "blue" => Color::BLUE,
-// "yellow" => Color::YELLOW,
-// "cyan" => Color::CYAN,
-// "magenta" => Color::MAGENTA,
-// "black" => Color::BLACK,
-// "light_white" => Color::LIGHT_WHITE,
-// "light_red" => Color::LIGHT_RED,
-// "light_green" => Color::LIGHT_GREEN,
-// "light_blue" => Color::LIGHT_BLUE,
-// "light_yellow" => Color::LIGHT_YELLOW,
-// "light_cyan" => Color::LIGHT_CYAN,
-// "light_magenta" => Color::LIGHT_MAGENTA,
-// "light_black" => Color::LIGHT_BLACK,
-// _ => Color::default(),
-// }
-// }
-
/// Returns a config with values from :
///
/// 1. hardcoded values
diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs
index c98a894..1ae3aa6 100644
--- a/src/event_dispatch.rs
+++ b/src/event_dispatch.rs
@@ -25,13 +25,7 @@ impl EventDispatcher {
/// Only non keyboard events are dealt here directly.
/// Keyboard events are configurable and are sent to specific functions
/// which needs to know those keybindings.
- pub fn dispatch(
- &self,
- status: &mut Status,
- ev: Event,
- // colors: &Colors,
- current_height: usize,
- ) -> Result<()> {
+ pub fn dispatch(&self, status: &mut Status, ev: Event, current_height: usize) -> Result<()> {
match ev {
Event::Key(Key::WheelUp(_, col, _)) => {
status.select_pane(col)?;
diff --git a/src/fileinfo.rs b/src/fileinfo.rs
index 3468c8f..881dcb7 100644
--- a/src/fileinfo.rs
+++ b/src/fileinfo.rs
@@ -10,7 +10,7 @@ use log::info;
use tuikit::prelude::{Attr, Color, Effect};
use users::{Groups, Users, UsersCache};
-use crate::color_cache::extension_color;
+use crate::colors::extension_color;
use crate::constant_strings_paths::PERMISSIONS_STR;
use crate::filter::FilterKind;
use crate::git::git;
@@ -566,17 +566,6 @@ fn fileinfo_color(fileinfo: &FileInfo) -> Color {
/// effect.
/// Selected file is reversed.
pub fn fileinfo_attr(fileinfo: &FileInfo) -> Attr {
- // let fg = match fileinfo.file_kind {
- // FileKind::Directory => str_to_tuikit(&colors.directory),
- // FileKind::BlockDevice => str_to_tuikit(&colors.block),
- // FileKind::CharDevice => str_to_tuikit(&colors.char),
- // FileKind::Fifo => str_to_tuikit(&colors.fifo),
- // FileKind::Socket => str_to_tuikit(&colors.socket),
- // FileKind::SymbolicLink(true) => str_to_tuikit(&colors.symlink),
- // FileKind::SymbolicLink(false) => str_to_tuikit(&colors.broken),
- // _ => extension_color(&fileinfo.extension),
- // // _ => colors.color_cache.extension_color(&fileinfo.extension),
- // };
let fg = fileinfo_color(fileinfo);
let effect = if fileinfo.is_selected {
diff --git a/src/lib.rs b/src/lib.rs
index 5fd6ff0..ef36e70 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,7 @@ pub mod action_map;
pub mod args;
pub mod bulkrename;
pub mod cli_info;
-pub mod color_cache;
+pub mod colors;
pub mod completion;
pub mod compress;
pub mod config;
diff --git a/src/main.rs b/src/main.rs
index 45e9ceb..113918c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,10 +29,6 @@ struct FM {
status: Status,
/// Responsible for the display on screen.
display: Display,
- // /// Colors used by different kind of files.
- // /// Since most are generated the first time an extension is met,
- // /// we need to hold this.
- // colors: Colors,
/// Refresher is used to force a refresh when a file has been modified externally.
/// It send `Event::Key(Key::AltPageUp)` every 10 seconds.
/// It also has a `mpsc::Sender` to send a quit message and reset the cursor.
@@ -45,7 +41,6 @@ impl FM {
/// an `EventDispatcher`,
/// a `Status`,
/// a `Display`,
- /// some `Colors`,
/// a `Refresher`.
/// It reads and drops the configuration from the config file.
/// If the config can't be parsed, it exits with error code 1.
diff --git a/src/term_manager.rs b/src/term_manager.rs
index ef7d915..0f63930 100644
--- a/src/term_manager.rs
+++ b/src/term_manager.rs
@@ -66,12 +66,6 @@ const ATTR_YELLOW_BOLD: Attr = Attr {
effect: Effect::BOLD,
};
-const ATTR_CYAN_BOLD: Attr = Attr {
- fg: Color::CYAN,
- bg: Color::Default,
- effect: Effect::BOLD,
-};
-
/// Simple struct to read the events.
pub struct EventReader {
term: Arc<Term>,
@@ -227,7 +221,7 @@ impl<'a> WinMain<'a> {
attr.effect ^= Effect::REVERSE;
if status.flagged.contains(&file.path) {
- canvas.print_with_attr(1, 0, "█", ATTR_CYAN_BOLD)?;
+ canvas.print_with_attr(1, 0, "█", ATTR_YELLOW_BOLD)?;
attr.effect |= Effect::BOLD;
}
Ok(canvas.print_with_attr(1, 1, &file.format(owner_size, group_size)?, attr)?)
@@ -382,7 +376,7 @@ impl<'a> WinMain<'a> {
};
if status.flagged.contains(&file.path) {
attr.effect |= Effect::BOLD;
- canvas.print_with_attr(row, 0, "█", ATTR_CYAN_BOLD)?;
+ canvas.print_with_attr(row, 0, "█", ATTR_YELLOW_BOLD)?;
}
canvas.print_with_attr(row, 1, &string, attr)?;
}
@@ -409,7 +403,7 @@ impl<'a> WinMain<'a> {
let mut attr = colored_string.attr;
if status.flagged.contains(&colored_string.path) {
attr.effect |= Effect::BOLD;
- canvas.print_with_attr(row, 0, "█", ATTR_CYAN_BOLD)?;
+ canvas.print_with_attr(row, 0, "█", ATTR_YELLOW_BOLD)?;
}
let col_metadata = if status.display_full {