Allow mux_env_remove={} to produce an empty vec
We need to do a little dance to get this to work because
`{}` is ambiguous in lua; could be a map or a vec.
refs: https://github.com/wez/wezterm/issues/1622
This commit is contained in:
1 parent
ace8253498
commit
89f20d265f
2 files changed
+58
-2
No files matched your search
@@ -15,7 +15,7 @@ use crate::units::{de_pixels, Dimension};
|
||||
use crate::unix::UnixDomain;
|
||||
use crate::wsl::WslDomain;
|
||||
use crate::{
|
||||
de_number, default_config_with_overrides_applied, default_one_point_oh,
|
||||
de_number, de_vec_table, default_config_with_overrides_applied, default_one_point_oh,
|
||||
default_one_point_oh_f64, default_true, make_lua_context, LoadedConfig, CONFIG_DIR,
|
||||
CONFIG_FILE_OVERRIDE, CONFIG_OVERRIDES, CONFIG_SKIP, HOME_DIR,
|
||||
};
|
||||
@@ -246,7 +246,7 @@ pub struct Config {
|
||||
#[serde(default = "default_mux_output_parser_buffer_size")]
|
||||
pub mux_output_parser_buffer_size: usize,
|
||||
|
||||
#[serde(default = "default_mux_env_remove")]
|
||||
#[serde(default = "default_mux_env_remove", deserialize_with = "de_vec_table")]
|
||||
pub mux_env_remove: Vec<String>,
|
||||
|
||||
#[serde(default)]
|
||||
|
||||
@@ -12,6 +12,7 @@ use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::DirBuilder;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::DirBuilderExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -702,6 +703,61 @@ where
|
||||
deserializer.deserialize_any(Number)
|
||||
}
|
||||
|
||||
pub fn de_vec_table<'de, D, T>(deserializer: D) -> Result<Vec<T>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
struct V<T> {
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'de, T> serde::de::Visitor<'de> for V<T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
type Value = Vec<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
formatter.write_str("Empty table or vector-like table")
|
||||
}
|
||||
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let mut values = if let Some(hint) = seq.size_hint() {
|
||||
Vec::with_capacity(hint)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
while let Some(ele) = seq.next_element::<T>()? {
|
||||
values.push(ele);
|
||||
}
|
||||
Ok(values)
|
||||
}
|
||||
|
||||
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: serde::de::MapAccess<'de>,
|
||||
{
|
||||
if map.next_entry::<String, T>()?.is_some() {
|
||||
use serde::de::Error;
|
||||
Err(A::Error::custom(
|
||||
"expected empty table or vector-like table",
|
||||
))
|
||||
} else {
|
||||
// Empty map is equivalent to empty vec
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_any(V {
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
pub struct LoadedConfig {
|
||||
pub config: Config,
|
||||
pub file_name: Option<PathBuf>,
|
||||
|
||||
Reference in new issue
Block a user