diff --git a/config/src/color.rs b/config/src/color.rs index d4f517308..f9a3d29a8 100644 --- a/config/src/color.rs +++ b/config/src/color.rs @@ -410,3 +410,36 @@ impl ColorSchemeFile { ColorSchemeFile::from_toml_value(&scheme) } } + +#[cfg(test)] +#[test] +fn test_indexed_colors() { + let scheme = r##" +[colors] +foreground = "#005661" +background = "#fef8ec" +cursor_bg = "#005661" +cursor_border = "#005661" +cursor_fg = "#ffffff" +selection_bg = "#cfe7f0" +selection_fg = "#005661" + +ansi = [ "#8ca6a6" ,"#e64100" ,"#00b368" ,"#fa8900" ,"#0095a8" ,"#ff5792" ,"#00bdd6" ,"#005661" ] +brights = [ "#8ca6a6" ,"#e5164a" ,"#00b368" ,"#b3694d" ,"#0094f0" ,"#ff5792" ,"#00bdd6" ,"#004d57" ] + +[colors.indexed] +52 = "#fbdada" # minus +88 = "#f6b6b6" # minus emph +22 = "#d6ffd6" # plus +28 = "#adffad" # plus emph +53 = "#feecf7" # purple +17 = "#e5dff6" # blue +23 = "#d8fdf6" # cyan +58 = "#f4ffe0" # yellow +"##; + let scheme = ColorSchemeFile::from_toml_str(scheme).unwrap(); + assert_eq!( + scheme.colors.indexed.get(&52), + Some(&RgbColor::new_8bpc(0xfb, 0xda, 0xda).into()) + ); +} diff --git a/config/src/lib.rs b/config/src/lib.rs index 83c018049..971c5b293 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -73,6 +73,10 @@ thread_local! { static LUA_CONFIG: RefCell> = RefCell::new(None); } +fn toml_table_has_numeric_keys(t: &toml::value::Table) -> bool { + t.keys().all(|k| k.parse::().is_ok()) +} + fn toml_to_dynamic(value: &toml::Value) -> Value { match value { toml::Value::String(s) => s.to_dynamic(), @@ -85,6 +89,13 @@ fn toml_to_dynamic(value: &toml::Value) -> Value { .map(|element| toml_to_dynamic(&element)) .collect::>() .to_dynamic(), + // Allow `colors.indexed` to be passed through with actual integer keys + toml::Value::Table(t) if toml_table_has_numeric_keys(t) => Value::Object( + t.iter() + .map(|(k, v)| (k.parse::().unwrap().to_dynamic(), toml_to_dynamic(v))) + .collect::>() + .into(), + ), toml::Value::Table(t) => Value::Object( t.iter() .map(|(k, v)| (Value::String(k.to_string()), toml_to_dynamic(v))) diff --git a/docs/changelog.md b/docs/changelog.md index 9d8c747e3..f2cef88d7 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -15,6 +15,7 @@ As features stabilize some brief notes about them will accumulate here. * [ActivateKeyTable](config/lua/keyassignment/ActivateKeyTable.md)'s `replace_current` field was not actually optional. Made it optional. [#2179](https://github.com/wez/wezterm/issues/2179) * `winget` causes toast notification spam [#2185](https://github.com/wez/wezterm/issues/2185) * `wezterm connect sshdomain` could hang on startup if password authentication was required [#2194](https://github.com/wez/wezterm/issues/2194) +* `colors.indexed` would error out with `Cannot convert String to u8`. [#2197](https://github.com/wez/wezterm/issues/2197) ### 20220624-141144-bd1b7c5d