Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(color-scale): Add EZA_MAX_LUMINANCE env var like EZA_MIN_LUMINANCE #1380

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ For more information on the format of these environment variables, see the [eza_
Overrides any `--git` or `--git-repos` argument

## `EZA_MIN_LUMINANCE`
Specifies the minimum luminance to use when color-scale is active. It's value can be between -100 to 100.
Specifies the minimum luminance to use when color-scale is active. Its value can be between -100 and 100.

## `EZA_MAX_LUMINANCE`
Specifies the maximum luminance to use when color-scale is active. Its value can be between -100 and 100.

## `EZA_ICONS_AUTO`

Expand Down
16 changes: 12 additions & 4 deletions src/options/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ pub static EZA_ICON_SPACING: &str = "EZA_ICON_SPACING";
pub static EXA_OVERRIDE_GIT: &str = "EXA_OVERRIDE_GIT";
pub static EZA_OVERRIDE_GIT: &str = "EZA_OVERRIDE_GIT";

/// Enviroment variable used to set the minimum luminance in `color_scale`. It's value
/// Environment variable used to set the minimum luminance in `color_scale`. Its value
/// can be between -100 and 100
pub static EXA_MIN_LUMINANCE: &str = "EXA_MIN_LUMINANCE";
pub static EZA_MIN_LUMINANCE: &str = "EZA_MIN_LUMINANCE";

/// Environment variable used to set the maximum luminance in `color_scale`. Its value
/// can be between -100 and 100
pub static EXA_MAX_LUMINANCE: &str = "EXA_MAX_LUMINANCE";
pub static EZA_MAX_LUMINANCE: &str = "EZA_MAX_LUMINANCE";

/// Environment variable used to automate the same behavior as `--icons=auto` if set.
/// Any explicit use of `--icons=WHEN` overrides this behavior.
pub static EZA_ICONS_AUTO: &str = "EZA_ICONS_AUTO";
Expand Down Expand Up @@ -115,7 +120,8 @@ pub struct MockVars {
debug: OsString,
grid_rows: OsString,
icon_spacing: OsString,
luminance: OsString,
min_luminance: OsString,
max_luminance: OsString,
icons: OsString,
}

Expand All @@ -129,7 +135,8 @@ impl Vars for MockVars {
"EXA_DEBUG" | "EZA_DEBUG" => Some(self.debug.clone()),
"EXA_GRID_ROWS" | "EZA_GRID_ROWS" => Some(self.grid_rows.clone()),
"EXA_ICON_SPACING" | "EZA_ICON_SPACING" => Some(self.icon_spacing.clone()),
"EXA_MIN_LUMINANCE" | "EZA_MIN_LUMINANCE" => Some(self.luminance.clone()),
"EXA_MIN_LUMINANCE" | "EZA_MIN_LUMINANCE" => Some(self.min_luminance.clone()),
"EXA_MAX_LUMINANCE" | "EZA_MAX_LUMINANCE" => Some(self.max_luminance.clone()),
"EZA_ICONS_AUTO" => Some(self.icons.clone()),
"COLUMNS" => Some(self.columns.clone()),
"NO_COLOR" => Some(self.no_colors.clone()),
Expand All @@ -148,7 +155,8 @@ impl MockVars {
"EXA_DEBUG" | "EZA_DEBUG" => self.debug = value.clone(),
"EXA_GRID_ROWS" | "EZA_GRID_ROWS" => self.grid_rows = value.clone(),
"EXA_ICON_SPACING" | "EZA_ICON_SPACING" => self.icon_spacing = value.clone(),
"EXA_MIN_LUMINANCE" | "EZA_MIN_LUMINANCE" => self.luminance = value.clone(),
"EXA_MIN_LUMINANCE" | "EZA_MIN_LUMINANCE" => self.min_luminance = value.clone(),
"EXA_MAX_LUMINANCE" | "EZA_MAX_LUMINANCE" => self.min_luminance = value.clone(),
"EZA_ICONS_AUTO" => self.icons = value.clone(),
"COLUMNS" => self.columns = value.clone(),
"NO_COLOR" => self.no_colors = value.clone(),
Expand Down
9 changes: 9 additions & 0 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ impl ColorScaleOptions {
},
None => 40,
};
let max_luminance =
match vars.get_with_fallback(vars::EZA_MAX_LUMINANCE, vars::EXA_MAX_LUMINANCE) {
Some(var) => match var.to_string_lossy().parse() {
Ok(luminance) if (-100..=100).contains(&luminance) => luminance,
_ => 100,
},
None => 100,
};

let mode = if let Some(w) = matches
.get(&flags::COLOR_SCALE_MODE)?
Expand All @@ -488,6 +496,7 @@ impl ColorScaleOptions {
let mut options = ColorScaleOptions {
mode,
min_luminance,
max_luminance,
size: false,
age: false,
};
Expand Down
7 changes: 5 additions & 2 deletions src/output/color_scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
pub struct ColorScaleOptions {
pub mode: ColorScaleMode,
pub min_luminance: isize,
pub max_luminance: isize,
pub size: bool,
pub age: bool,
}
Expand All @@ -26,6 +27,7 @@ impl Default for ColorScaleOptions {
Self {
mode: ColorScaleMode::Fixed,
min_luminance: 50,
max_luminance: 100,
size: false,
age: false,
}
Expand Down Expand Up @@ -96,6 +98,7 @@ impl ColorScaleInformation {
fg,
ratio,
self.options.min_luminance as f32 / 100.0,
self.options.max_luminance as f32 / 100.0,
));
}

Expand Down Expand Up @@ -217,7 +220,7 @@ impl Extremes {
}
}

fn adjust_luminance(color: Colour, x: f32, min_l: f32) -> Colour {
fn adjust_luminance(color: Colour, x: f32, min_l: f32, max_l: f32) -> Colour {
let rgb_color = match color {
Colour::Rgb(r, g, b) => LinSrgb::new(
f32::from(r) / 255.0,
Expand Down Expand Up @@ -251,7 +254,7 @@ fn adjust_luminance(color: Colour, x: f32, min_l: f32) -> Colour {
};

let mut lab: Oklab = Oklab::from_color(rgb_color);
lab.l = (min_l + (1.0 - min_l) * (-4.0 * (1.0 - x)).exp()).clamp(0.0, 1.0);
lab.l = (min_l + (max_l - min_l) * (-4.0 * (1.0 - x)).exp()).clamp(0.0, 1.0);

let adjusted_rgb: Srgb<f32> = Srgb::from_color(lab);
Colour::Rgb(
Expand Down
9 changes: 9 additions & 0 deletions src/output/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const FILENAME_ICONS: Map<&'static str, char> = phf_map! {
".editorconfig" => '\u{e652}', // 
".emacs" => Icons::EMACS, // 
".envrc" => '\u{f462}', // 
".eslintignore" => Icons::ESLINT, // 
".eslintrc.cjs" => Icons::ESLINT, // 
".eslintrc.js" => Icons::ESLINT, // 
".eslintrc.json" => Icons::ESLINT, // 
Expand Down Expand Up @@ -242,6 +243,7 @@ const FILENAME_ICONS: Map<&'static str, char> = phf_map! {
".npmignore" => Icons::NPM, // 
".npmrc" => Icons::NPM, // 
".pre-commit-config.yaml" => '\u{f06e2}', // 󰛢
".prettierignore" => '\u{e6b4}', // 
".prettierrc" => '\u{e6b4}', // 
".parentlock" => Icons::LOCK, // 
".profile" => Icons::SHELL, // 󱆃
Expand Down Expand Up @@ -381,6 +383,7 @@ const FILENAME_ICONS: Map<&'static str, char> = phf_map! {
"Makefile.in" => Icons::MAKE, // 
"MANIFEST" => Icons::LANG_PYTHON, // 
"MANIFEST.in" => Icons::LANG_PYTHON, // 
"mix.lock" => Icons::LANG_ELIXIR, // 
"mpv.conf" => '\u{f36e}', // 
"npm-shrinkwrap.json" => Icons::NPM, // 
"npmrc" => Icons::NPM, // 
Expand All @@ -404,6 +407,7 @@ const FILENAME_ICONS: Map<&'static str, char> = phf_map! {
"README" => Icons::README, // 󰂺
"README.md" => Icons::README, // 󰂺
"release.toml" => Icons::LANG_RUST, // 
"renovate.json" => '\u{f027c}', // 󰉼
"requirements.txt" => Icons::LANG_PYTHON, // 
"robots.txt" => '\u{f06a9}', // 󰚩
"rubydoc" => Icons::LANG_RUBYRAILS, // 
Expand Down Expand Up @@ -560,6 +564,8 @@ const EXTENSION_ICONS: Map<&'static str, char> = phf_map! {
"dylib" => Icons::OS_APPLE, // 
"ebook" => Icons::BOOK, // 
"ebuild" => '\u{f30d}', // 
"editorconfig" => '\u{e652}', // 
"eex" => Icons::LANG_ELIXIR, // 
"ejs" => '\u{e618}', // 
"el" => Icons::EMACS, // 
"elc" => Icons::EMACS, // 
Expand Down Expand Up @@ -656,6 +662,7 @@ const EXTENSION_ICONS: Map<&'static str, char> = phf_map! {
"hex" => '\u{f12a7}', // 󱊧
"hh" => Icons::LANG_CPP, // 
"hpp" => Icons::LANG_CPP, // 
"hrl" => '\u{e7b1}', // 
"hs" => Icons::LANG_HASKELL, // 
"htm" => Icons::HTML5, // 
"html" => Icons::HTML5, // 
Expand Down Expand Up @@ -728,6 +735,7 @@ const EXTENSION_ICONS: Map<&'static str, char> = phf_map! {
"lbr" => Icons::LIBRARY, // 
"lck" => Icons::LOCK, // 
"ldb" => Icons::DATABASE, // 
"leex" => Icons::LANG_ELIXIR, // 
"less" => '\u{e758}', // 
"lff" => Icons::FONT, // 
"lhs" => Icons::LANG_HASKELL, // 
Expand Down Expand Up @@ -847,6 +855,7 @@ const EXTENSION_ICONS: Map<&'static str, char> = phf_map! {
"prql" => Icons::DATABASE, // 
"ps" => Icons::VECTOR, // 󰕙
"ps1" => Icons::POWERSHELL, // 
"psb" => '\u{e7b8}', // 
"psd" => '\u{e7b8}', // 
"psd1" => Icons::POWERSHELL, // 
"psf" => Icons::FONT, // 
Expand Down