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_FILE");
std::env::remove_var("WEZTERM_CONFIG_DIR"); std::env::remove_var("WEZTERM_CONFIG_DIR");
fn try_default() -> anyhow::Result<LoadedConfig> { match Self::try_default() {
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() {
Err(err) => LoadedConfig { Err(err) => LoadedConfig {
config: Err(err), config: Err(err),
file_name: None, 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( fn try_load(
path_item: &PathPossibility, path_item: &PathPossibility,
overrides: &wezterm_dynamic::Value, 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<()> { pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow::Result<()> {
term.no_grab_mouse_in_raw_mode(); term.no_grab_mouse_in_raw_mode();
let config::LoadedConfig { let config::LoadedConfig { lua, .. } = config::Config::load();
lua, // Try hard to fall back to some kind of working lua context even
config, // if the user's config file is temporarily out of whack
file_name: _, let lua = match lua {
} = config::Config::load(); Some(lua) => lua,
config?; None => match config::Config::try_default() {
let lua = lua.ok_or_else(|| anyhow::anyhow!("failed to setup lua context"))?; Ok(config::LoadedConfig { lua: Some(lua), .. }) => lua,
_ => config::lua::make_lua_context(std::path::Path::new(""))?,
},
};
lua.load("wezterm = require 'wezterm'").exec()?; lua.load("wezterm = require 'wezterm'").exec()?;
lua.globals().set("window", gui_win)?; lua.globals().set("window", gui_win)?;