Commit 4348ffda60

4348ffda60d1fb907e1cf6e4f6891a962cf711c4

parent: 172d66adb3

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-10-13 03:11 UTC
committer: <noreply@github.com>

Add `rainbow-light` and `rainbow-dark` username palettes (#812)

Layout: unified · split

Cargo.lock +3
@@ -2569,6 +2569,7 @@ dependencies = [
2569 "nom 8.0.0", 2569 "nom 8.0.0",
2570 "notify-rust", 2570 "notify-rust",
2571 "open", 2571 "open",
2572 "palette",
2572 "percent-encoding", 2573 "percent-encoding",
2573 "pretty_assertions", 2574 "pretty_assertions",
2574 "ratatui", 2575 "ratatui",
@@ -4271,6 +4272,7 @@ dependencies = [
4271 "libm", 4272 "libm",
4272 "palette_derive", 4273 "palette_derive",
4273 "palette_math", 4274 "palette_math",
4275 "phf 0.13.1",
4274] 4276]
4275 4277
4276[[package]] 4278[[package]]
@@ -4984,6 +4986,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
4984checksum = "3274ba0a2c5e1bcad2a2005d20f4dc59dad26b2eb0940fb094500dba4099d57d" 4986checksum = "3274ba0a2c5e1bcad2a2005d20f4dc59dad26b2eb0940fb094500dba4099d57d"
4985dependencies = [ 4987dependencies = [
4986 "instability", 4988 "instability",
4989 "palette",
4987 "ratatui-core", 4990 "ratatui-core",
4988 "ratatui-crossterm", 4991 "ratatui-crossterm",
4989 "ratatui-macros", 4992 "ratatui-macros",
Cargo.toml +2 −1
@@ -39,6 +39,7 @@ css-color-parser = "0.1.2"
39dirs = "7.0" 39dirs = "7.0"
40edit = "0.1.4" 40edit = "0.1.4"
41emojis = "0.9" 41emojis = "0.9"
42palette = "0.7.7"
42feruca = "0.12" 43feruca = "0.12"
43futures = "0.3" 44futures = "0.3"
44gethostname = "1.1" 45gethostname = "1.1"
@@ -55,7 +56,7 @@ mime = "0.3.16"
55mime_guess = "2.0.4" 56mime_guess = "2.0.4"
56nom = "8.0" 57nom = "8.0"
57open = "5.0.0" 58open = "5.0.0"
58ratatui = { version = "0.30.2", features = ["serde"] } 59ratatui = { version = "0.30.2", features = ["palette", "serde"] }
59regex = "1.5" 60regex = "1.5"
60rpassword = "7.2" 61rpassword = "7.2"
61serde = "1.0" 62serde = "1.0"
docs/iamb.5 +6 −1
@@ -940,7 +940,12 @@ and
940.Sy modifiers 940.Sy modifiers
941properties, you can also specify a 941properties, you can also specify a
942.Sy colors 942.Sy colors
943array for providing a broad palette of colors from which to style usernames. 943field for providing a broad palette of colors from which to style usernames.
944You can provide an array of specific colors, which you may want if you have a list of specific colors that work for your theme, but you can also set it to
945.Sy "rainbow-light"
946or
947.Sy "rainbow-dark"
948to use a large light- or dark-colored rainbow palette for usernames.
944.Pp 949.Pp
945By default, this is a selection of 13 standard ANSI colors that should look okay on both light and dark backgrounds. 950By default, this is a selection of 13 standard ANSI colors that should look okay on both light and dark backgrounds.
946You can set this array to 951You can set this array to
src/config/theme.rs +63 −18
@@ -3,6 +3,7 @@ use std::collections::hash_map::DefaultHasher;
3use std::hash::{Hash, Hasher}; 3use std::hash::{Hash, Hasher};
4 4
5use anyhow::Context; 5use anyhow::Context;
6use palette::Hsl;
6use ratatui::widgets::BorderType; 7use ratatui::widgets::BorderType;
7use serde::de::Error as SerdeError; 8use serde::de::Error as SerdeError;
8use serde::de::Visitor; 9use serde::de::Visitor;
@@ -93,7 +94,7 @@ pub fn default_theme() -> Theme {
93 ..Default::default() 94 ..Default::default()
94 }, 95 },
95 users: ThemeUsers { 96 users: ThemeUsers {
96 colors: Some(vec![ 97 colors: Some(UserColors::Palette(vec![
97 Color::Blue, 98 Color::Blue,
98 Color::Cyan, 99 Color::Cyan,
99 Color::Green, 100 Color::Green,
@@ -107,7 +108,7 @@ pub fn default_theme() -> Theme {
107 Color::Red, 108 Color::Red,
108 Color::Reset, 109 Color::Reset,
109 Color::Yellow, 110 Color::Yellow,
110 ]), 111 ])),
111 stylable: Stylable::with_modifiers(StyleModifier::BOLD), 112 stylable: Stylable::with_modifiers(StyleModifier::BOLD),
112 }, 113 },
113 ..Default::default() 114 ..Default::default()
@@ -1042,9 +1043,61 @@ pub struct ThemeWindowsValues {
1042 pub title: Style, 1043 pub title: Style,
1043} 1044}
1044 1045
1046#[derive(Clone, Debug, Default, Deserialize)]
1047#[serde(rename_all = "kebab-case")]
1048enum UserColors {
1049 RainbowDark,
1050 RainbowLight,
1051 #[default]
1052 #[serde(skip)]
1053 Unset,
1054 #[serde(untagged)]
1055 Palette(Vec<Color>),
1056}
1057
1058impl UserColors {
1059 fn hash(user_id: &str) -> u64 {
1060 let mut hasher = DefaultHasher::new();
1061 user_id.hash(&mut hasher);
1062 hasher.finish()
1063 }
1064
1065 fn hash_to_color(hash: f64, l_base: f64) -> Color {
1066 let h = hash % 360.0;
1067 let s = hash % 60.0 + 40.0;
1068 let l = hash % 35.0 + l_base;
1069 let hsl: Hsl = Hsl::new(h as f32, s as f32 / 100.0, l as f32 / 100.0);
1070 Color::from_hsl(hsl)
1071 }
1072
1073 fn color(&self, user_id: &str) -> Option<Color> {
1074 let color = match self {
1075 Self::Unset => return None,
1076 Self::Palette(colors) => {
1077 if colors.is_empty() {
1078 return None;
1079 } else {
1080 let hash = Self::hash(user_id) as usize;
1081 colors[hash % colors.len()]
1082 }
1083 },
1084 Self::RainbowDark => {
1085 let hash = Self::hash(user_id);
1086 Self::hash_to_color(hash as f64, 15.0)
1087 },
1088 Self::RainbowLight => {
1089 let hash = Self::hash(user_id);
1090 Self::hash_to_color(hash as f64, 50.0)
1091 },
1092 };
1093
1094 Some(color)
1095 }
1096}
1097
1045#[derive(Clone, Debug, Default, Deserialize)] 1098#[derive(Clone, Debug, Default, Deserialize)]
1046struct ThemeUsers { 1099struct ThemeUsers {
1047 colors: Option<Vec<Color>>, 1100 colors: Option<UserColors>,
1048 #[serde(flatten)] 1101 #[serde(flatten)]
1049 stylable: Stylable, 1102 stylable: Stylable,
1050} 1103}
@@ -1058,8 +1111,8 @@ impl ThemeUsers {
1058 } 1111 }
1059 1112
1060 fn values(self, base: Style) -> ThemeUsersValues { 1113 fn values(self, base: Style) -> ThemeUsersValues {
1061 let colors = self.colors.unwrap_or_default();
1062 let style = base.patch(self.stylable); 1114 let style = base.patch(self.stylable);
1115 let colors = self.colors.unwrap_or_default();
1063 1116
1064 ThemeUsersValues { colors, style } 1117 ThemeUsersValues { colors, style }
1065 } 1118 }
@@ -1067,20 +1120,13 @@ impl ThemeUsers {
1067 1120
1068#[derive(Clone, Debug, Default)] 1121#[derive(Clone, Debug, Default)]
1069pub struct ThemeUsersValues { 1122pub struct ThemeUsersValues {
1070 colors: Vec<Color>, 1123 colors: UserColors,
1071 style: Style, 1124 style: Style,
1072} 1125}
1073 1126
1074impl ThemeUsersValues { 1127impl ThemeUsersValues {
1075 pub fn color(&self, user_id: &str) -> Color { 1128 pub fn color(&self, user_id: &str) -> Color {
1076 if self.colors.is_empty() { 1129 self.colors.color(user_id).or(self.style.fg).unwrap_or(Color::Reset)
1077 return self.style.fg.unwrap_or(Color::Reset);
1078 }
1079
1080 let mut hasher = DefaultHasher::new();
1081 user_id.hash(&mut hasher);
1082 let color = hasher.finish() as usize % self.colors.len();
1083 self.colors[color]
1084 } 1130 }
1085 1131
1086 pub fn style(&self, user_id: &str, explicit: Option<Color>) -> Style { 1132 pub fn style(&self, user_id: &str, explicit: Option<Color>) -> Style {
@@ -1089,12 +1135,11 @@ impl ThemeUsersValues {
1089 if let Some(c) = explicit { 1135 if let Some(c) = explicit {
1090 // Use explicit color from config file: 1136 // Use explicit color from config file:
1091 style.fg(c) 1137 style.fg(c)
1092 } else if self.colors.is_empty() { 1138 } else if let Some(c) = self.colors.color(user_id) {
1093 // User has explicitly set an empty array: 1139 // Apply the user color we hashed to:
1094 style 1140 style.fg(c)
1095 } else { 1141 } else {
1096 // Hash on user ID to pick a color from the array: 1142 style
1097 style.fg(self.color(user_id))
1098 } 1143 }
1099 } 1144 }
1100} 1145}