From d2ed0152f1a48bec3b84e5602944221ddf13071f Mon Sep 17 00:00:00 2001 From: Robert Martin Winterstein Date: Sun, 7 Oct 2018 15:10:58 -0600 Subject: [PATCH] fix erroneous indexed_color results --- CHANGELOG.md | 3 +++ src/term/color.rs | 17 ++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac29fb06..155cb5ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed erroneous results when using the `indexed_colors` config option + ## Version 0.2.1 ### Added diff --git a/src/term/color.rs b/src/term/color.rs index 276a6897..0706f9df 100644 --- a/src/term/color.rs +++ b/src/term/color.rs @@ -101,24 +101,19 @@ impl List { for r in 0..6 { for g in 0..6 { for b in 0..6 { - // Index of the color is number of named colors + rgb - let color_index = 16 + r + g + b; - // Override colors 16..232 with the config (if present) if let Some(indexed_color) = colors .indexed_colors .iter() - .find(|ic| ic.index == color_index) + .find(|ic| ic.index == index as u8) { self[index] = indexed_color.color; - index += 1; - continue; + } else { + self[index] = Rgb { r: if r == 0 { 0 } else { r * 40 + 55 }, + b: if b == 0 { 0 } else { b * 40 + 55 }, + g: if g == 0 { 0 } else { g * 40 + 55 }, + }; } - - self[index] = Rgb { r: if r == 0 { 0 } else { r * 40 + 55 }, - b: if b == 0 { 0 } else { b * 40 + 55 }, - g: if g == 0 { 0 } else { g * 40 + 55 }, - }; index += 1; } }