1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

allow debug overlay to open even if the config file is busted

refs: https://github.com/wez/wezterm/issues/1174
This commit is contained in:
Wez Furlong 2022-06-29 14:47:45 -07:00
parent eb50c68228
commit d23414105e
2 changed files with 22 additions and 18 deletions

View File

@ -731,17 +731,7 @@ impl Config {
std::env::remove_var("WEZTERM_CONFIG_FILE");
std::env::remove_var("WEZTERM_CONFIG_DIR");
fn try_default() -> anyhow::Result<LoadedConfig> {
let config = default_config_with_overrides_applied()?.compute_extra_defaults(None);
Ok(LoadedConfig {
config: Ok(config),
file_name: None,
lua: Some(make_lua_context(Path::new(""))?),
})
}
match try_default() {
match Self::try_default() {
Err(err) => LoadedConfig {
config: Err(err),
file_name: None,
@ -751,6 +741,16 @@ impl Config {
}
}
pub fn try_default() -> anyhow::Result<LoadedConfig> {
let config = default_config_with_overrides_applied()?.compute_extra_defaults(None);
Ok(LoadedConfig {
config: Ok(config),
file_name: None,
lua: Some(make_lua_context(Path::new(""))?),
})
}
fn try_load(
path_item: &PathPossibility,
overrides: &wezterm_dynamic::Value,

View File

@ -130,13 +130,17 @@ impl LineEditorHost for LuaReplHost {
pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow::Result<()> {
term.no_grab_mouse_in_raw_mode();
let config::LoadedConfig {
lua,
config,
file_name: _,
} = config::Config::load();
config?;
let lua = lua.ok_or_else(|| anyhow::anyhow!("failed to setup lua context"))?;
let config::LoadedConfig { lua, .. } = config::Config::load();
// Try hard to fall back to some kind of working lua context even
// if the user's config file is temporarily out of whack
let lua = match lua {
Some(lua) => lua,
None => match config::Config::try_default() {
Ok(config::LoadedConfig { lua: Some(lua), .. }) => lua,
_ => config::lua::make_lua_context(std::path::Path::new(""))?,
},
};
lua.load("wezterm = require 'wezterm'").exec()?;
lua.globals().set("window", gui_win)?;