From 04299cb4c9acee24b6ca834ead343248b6293501 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 19 Aug 2023 18:06:12 -0700 Subject: [PATCH] Remove RgbColor::description This was unused; deriving Debug is sufficient. --- fish-rust/src/color.rs | 22 ---------------------- src/color.cpp | 38 -------------------------------------- src/color.h | 3 --- 3 files changed, 63 deletions(-) diff --git a/fish-rust/src/color.rs b/fish-rust/src/color.rs index b34ded22d..54f59c2b7 100644 --- a/fish-rust/src/color.rs +++ b/fish-rust/src/color.rs @@ -184,22 +184,6 @@ pub fn set_reverse(&mut self, reverse: bool) { self.flags.reverse = reverse; } - /// Returns a description of the color. - #[widestrs] - pub fn description(self) -> WString { - match self.typ { - Type::None => WString::from_str("none"), - Type::Named { idx } => { - sprintf!("named(%d, %ls)"L, idx, name_for_color_idx(idx).unwrap()) - } - Type::Rgb(c) => { - sprintf!("rgb(0x%02x%02x%02x"L, c.r, c.g, c.b) - } - Type::Normal => WString::from_str("normal"), - Type::Reset => WString::from_str("reset"), - } - } - /// Returns the name index for the given color. Requires that the color be named or RGB. pub fn to_name_index(self) -> u8 { // TODO: This should look for the nearest color. @@ -387,12 +371,6 @@ fn squared_difference(a: u8, b: u8) -> u32 { .0 } -fn name_for_color_idx(target_idx: u8) -> Option<&'static wstr> { - NAMED_COLORS - .iter() - .find_map(|&NamedColor { name, idx, .. }| (idx == target_idx).then_some(name)) -} - fn term16_color_for_rgb(color: Color24) -> u8 { const COLORS: &[u32] = &[ 0x000000, // Black diff --git a/src/color.cpp b/src/color.cpp index 070364b2f..bb8e2ed42 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -178,18 +178,6 @@ bool rgb_color_t::try_parse_named(const wcstring &str) { return false; } -static const wchar_t *name_for_color_idx(uint8_t idx) { - constexpr size_t colors_count = sizeof(named_colors) / sizeof(named_colors[0]); - if (idx < colors_count) { - for (auto &color : named_colors) { - if (idx == color.idx) { - return color.name; - } - } - } - return L"unknown"; -} - rgb_color_t::rgb_color_t(uint8_t t, uint8_t i) : type(t), flags(), data() { data.name_idx = i; } rgb_color_t rgb_color_t::normal() { return rgb_color_t(type_normal); } @@ -290,29 +278,3 @@ rgb_color_t::rgb_color_t(const wcstring &str) : type(), flags() { this->parse(st rgb_color_t::rgb_color_t(const std::string &str) : type(), flags() { this->parse(str2wcstring(str)); } - -wcstring rgb_color_t::description() const { - switch (type) { - case type_none: { - return L"none"; - } - case type_named: { - return format_string(L"named(%d: %ls)", static_cast(data.name_idx), - name_for_color_idx(data.name_idx)); - } - case type_rgb: { - return format_string(L"rgb(0x%02x%02x%02x)", data.color.rgb[0], data.color.rgb[1], - data.color.rgb[2]); - } - case type_reset: { - return L"reset"; - } - case type_normal: { - return L"normal"; - } - default: { - break; - } - } - DIE("unknown color type"); -} diff --git a/src/color.h b/src/color.h index 2097afc31..08c581fb8 100644 --- a/src/color.h +++ b/src/color.h @@ -91,9 +91,6 @@ class rgb_color_t { /// Returns whether the color is special, that is, not rgb or named. bool is_special(void) const { return type != type_named && type != type_rgb; } - /// Returns a description of the color. - wcstring description() const; - /// Returns the name index for the given color. Requires that the color be named or RGB. uint8_t to_name_index() const;