config: avoid storing default color schemes in config object
This helps keep the config object a bit smaller and the trace logging output less verbose. We now memoize the effective palette in the config, which should shave off a little bit of time in the renderer.
This commit is contained in:
1 parent
ad7362d3f7
commit
e3f91afeda
4 files changed
+41
-47
No files matched your search
+1
-1
@@ -13,7 +13,7 @@ pub struct HsbTransform {
|
||||
pub brightness: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
#[derive(Default, Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct Palette {
|
||||
/// The text color to use when the attributes are reset to default
|
||||
pub foreground: Option<RgbColor>,
|
||||
|
||||
+37
-17
@@ -63,12 +63,23 @@ lazy_static! {
|
||||
static ref SHOW_ERROR: Mutex<Option<ErrorCallback>> =
|
||||
Mutex::new(Some(|e| log::error!("{}", e)));
|
||||
static ref LUA_PIPE: LuaPipe = LuaPipe::new();
|
||||
static ref COLOR_SCHEMES: HashMap<String, Palette> = build_default_schemes();
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static LUA_CONFIG: RefCell<Option<LuaConfigState>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn build_default_schemes() -> HashMap<String, Palette> {
|
||||
let mut color_schemes = HashMap::new();
|
||||
for (scheme_name, data) in SCHEMES.iter() {
|
||||
let scheme_name = scheme_name.to_string();
|
||||
let scheme: ColorSchemeFile = toml::from_str(data).unwrap();
|
||||
color_schemes.insert(scheme_name, scheme.colors);
|
||||
}
|
||||
color_schemes
|
||||
}
|
||||
|
||||
struct LuaPipe {
|
||||
sender: Sender<mlua::Lua>,
|
||||
receiver: Receiver<mlua::Lua>,
|
||||
@@ -483,6 +494,9 @@ pub struct Config {
|
||||
/// The color palette
|
||||
pub colors: Option<Palette>,
|
||||
|
||||
#[serde(skip)]
|
||||
pub resolved_palette: Palette,
|
||||
|
||||
/// Use a named color scheme rather than the palette specified
|
||||
/// by the colors setting.
|
||||
pub color_scheme: Option<String>,
|
||||
@@ -1053,14 +1067,20 @@ impl Config {
|
||||
cfg.load_color_schemes(&cfg.compute_color_scheme_dirs())
|
||||
.ok();
|
||||
|
||||
cfg.resolved_palette = cfg.colors.as_ref().cloned().unwrap_or(Default::default());
|
||||
// Color scheme overrides any manually specified palette
|
||||
if let Some(scheme) = cfg.color_scheme.as_ref() {
|
||||
if !cfg.color_schemes.contains_key(scheme) {
|
||||
log::error!(
|
||||
"Your configuration specifies \
|
||||
color_scheme=\"{}\" but that scheme \
|
||||
was not found",
|
||||
scheme
|
||||
);
|
||||
match cfg.resolve_color_scheme() {
|
||||
None => {
|
||||
log::error!(
|
||||
"Your configuration specifies color_scheme=\"{}\" \
|
||||
but that scheme was not found",
|
||||
scheme
|
||||
);
|
||||
}
|
||||
Some(p) => {
|
||||
cfg.resolved_palette = p.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,19 +1147,19 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
for (scheme_name, data) in SCHEMES.iter() {
|
||||
let scheme_name = scheme_name.to_string();
|
||||
if self.color_schemes.contains_key(&scheme_name) {
|
||||
// This scheme has already been defined
|
||||
continue;
|
||||
}
|
||||
let scheme: ColorSchemeFile = toml::from_str(data).unwrap();
|
||||
self.color_schemes.insert(scheme_name, scheme.colors);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resolve_color_scheme(&self) -> Option<&Palette> {
|
||||
let scheme_name = self.color_scheme.as_ref()?;
|
||||
|
||||
if let Some(palette) = self.color_schemes.get(scheme_name) {
|
||||
Some(palette)
|
||||
} else {
|
||||
COLOR_SCHEMES.get(scheme_name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initial_size(&self) -> PtySize {
|
||||
PtySize {
|
||||
rows: self.initial_rows,
|
||||
|
||||
+1
-12
@@ -28,17 +28,6 @@ impl wezterm_term::TerminalConfiguration for TermConfig {
|
||||
fn color_palette(&self) -> ColorPalette {
|
||||
let config = configuration();
|
||||
|
||||
if let Some(scheme_name) = config.color_scheme.as_ref() {
|
||||
if let Some(palette) = config.color_schemes.get(scheme_name) {
|
||||
return palette.clone().into();
|
||||
}
|
||||
}
|
||||
|
||||
config
|
||||
.colors
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(ColorPalette::default)
|
||||
config.resolved_palette.clone().into()
|
||||
}
|
||||
}
|
||||
@@ -316,24 +316,9 @@ impl Pane for ClientPane {
|
||||
fn palette(&self) -> ColorPalette {
|
||||
let tardy = self.renderable.borrow().inner.borrow().is_tardy();
|
||||
|
||||
let palette = || {
|
||||
let config = configuration();
|
||||
let config = configuration();
|
||||
let palette: ColorPalette = config.resolved_palette.clone().into();
|
||||
|
||||
if let Some(scheme_name) = config.color_scheme.as_ref() {
|
||||
if let Some(palette) = config.color_schemes.get(scheme_name) {
|
||||
return palette.clone().into();
|
||||
}
|
||||
}
|
||||
|
||||
config
|
||||
.colors
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(ColorPalette::default)
|
||||
};
|
||||
|
||||
let palette = palette();
|
||||
if tardy {
|
||||
palette.grey_out()
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user