From 742fe5f462a4a62027a84dda085fcb1a8c19c92e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 26 Jul 2022 21:11:38 -0700 Subject: [PATCH] wezterm.format: now supports rgba colors ``` > wezterm.format{{Background={Color="rgba(255,0,0,0.5)"}}, {Text="wat"}} "\u{1b}[48:4::255:0:0:127mwat\u{1b}[49m" ``` --- lua-api-crates/termwiz-funcs/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua-api-crates/termwiz-funcs/src/lib.rs b/lua-api-crates/termwiz-funcs/src/lib.rs index 37a371d3f..7b96b494f 100644 --- a/lua-api-crates/termwiz-funcs/src/lib.rs +++ b/lua-api-crates/termwiz-funcs/src/lib.rs @@ -1,9 +1,10 @@ use config::lua::get_or_create_module; use config::lua::mlua::{self, Lua, ToLua}; use luahelper::impl_lua_conversion_dynamic; +use std::str::FromStr; use termwiz::caps::{Capabilities, ColorLevel, ProbeHints}; use termwiz::cell::{grapheme_column_width, unicode_column_width, AttributeChange, CellAttributes}; -use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, RgbColor}; +use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, SrgbaTuple}; use termwiz::input::Modifiers; use termwiz::render::terminfo::TerminfoRenderer; use termwiz::surface::change::Change; @@ -84,9 +85,8 @@ impl Into for FormatColor { match self { FormatColor::AnsiColor(c) => c.into(), FormatColor::Color(s) => { - let rgb = RgbColor::from_named_or_rgb_string(&s) - .unwrap_or(RgbColor::new_8bpc(0xff, 0xff, 0xff)); - rgb.into() + let rgba = SrgbaTuple::from_str(&s).unwrap_or_else(|()| (0xff, 0xff, 0xff).into()); + rgba.into() } FormatColor::Default => ColorSpec::Default, }