Show a window with the full error message for failed config load
This is a very basic first approximation for the feature discussed in the associated github issue. Refs: https://github.com/wez/wezterm/issues/80
This commit is contained in:
1 parent
51545ab099
commit
894e971e25
6 files changed
+64
-16
No files matched your search
Generated
+1
@@ -3298,6 +3298,7 @@ dependencies = [
|
||||
"tabout",
|
||||
"term",
|
||||
"termwiz",
|
||||
"textwrap",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"uds_windows",
|
||||
|
||||
@@ -54,6 +54,7 @@ structopt = "0.2"
|
||||
tabout = { path = "tabout" }
|
||||
term = { path = "term" }
|
||||
termwiz = { path = "termwiz"}
|
||||
textwrap = "0.11"
|
||||
toml = "0.4"
|
||||
unicode-normalization = "0.1"
|
||||
unicode-segmentation = "1.5"
|
||||
|
||||
+1
-2
@@ -155,8 +155,7 @@ impl ConfigInner {
|
||||
}
|
||||
Err(err) => {
|
||||
let err = format!("{:#}", err);
|
||||
log::error!("While (re)loading configuration: {}", err);
|
||||
crate::toast_notification("Wezterm Configuration", &err);
|
||||
crate::termwiztermtab::show_configuration_error_message(&err);
|
||||
self.error.replace(err);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-6
@@ -6,6 +6,7 @@ use downcast_rs::{impl_downcast, Downcast};
|
||||
use serde::Deserialize;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
pub mod activity;
|
||||
pub mod gui;
|
||||
@@ -29,6 +30,15 @@ thread_local! {
|
||||
static FRONT_END: RefCell<Option<Rc<dyn FrontEnd>>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
static HAS_GUI_FRONT_END: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// Returns true if a GUI frontend has been initialized, which implies that
|
||||
/// it makes sense (and is safe) to use the window crate and associated
|
||||
/// functionality
|
||||
pub fn has_gui_front_end() -> bool {
|
||||
HAS_GUI_FRONT_END.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn front_end() -> Option<Rc<dyn FrontEnd>> {
|
||||
let mut res = None;
|
||||
FRONT_END.with(|f| {
|
||||
@@ -41,14 +51,17 @@ pub fn front_end() -> Option<Rc<dyn FrontEnd>> {
|
||||
|
||||
impl FrontEndSelection {
|
||||
pub fn try_new(self) -> Result<Rc<dyn FrontEnd>, Error> {
|
||||
let front_end = match self {
|
||||
FrontEndSelection::MuxServer => muxserver::MuxServerFrontEnd::try_new(),
|
||||
FrontEndSelection::Null => muxserver::MuxServerFrontEnd::new_null(),
|
||||
FrontEndSelection::Software => gui::GuiFrontEnd::try_new_no_opengl(),
|
||||
FrontEndSelection::OpenGL => gui::GuiFrontEnd::try_new(),
|
||||
}?;
|
||||
let (front_end, is_gui) = match self {
|
||||
FrontEndSelection::MuxServer => (muxserver::MuxServerFrontEnd::try_new(), false),
|
||||
FrontEndSelection::Null => (muxserver::MuxServerFrontEnd::new_null(), false),
|
||||
FrontEndSelection::Software => (gui::GuiFrontEnd::try_new_no_opengl(), true),
|
||||
FrontEndSelection::OpenGL => (gui::GuiFrontEnd::try_new(), true),
|
||||
};
|
||||
|
||||
let front_end = front_end?;
|
||||
|
||||
FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));
|
||||
HAS_GUI_FRONT_END.store(is_gui, Ordering::Release);
|
||||
|
||||
Ok(front_end)
|
||||
}
|
||||
|
||||
+11
-8
@@ -411,6 +411,7 @@ fn run_ssh(config: config::ConfigHandle, opts: SshCommand) -> anyhow::Result<()>
|
||||
drop(activity);
|
||||
});
|
||||
|
||||
maybe_show_configuration_error_window();
|
||||
gui.run_forever()
|
||||
}
|
||||
|
||||
@@ -435,6 +436,7 @@ fn run_serial(config: config::ConfigHandle, opts: &SerialCommand) -> anyhow::Res
|
||||
let tab = block_on(domain.spawn(PtySize::default(), None, None, window_id))?; // FIXME: blocking
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
|
||||
maybe_show_configuration_error_window();
|
||||
gui.run_forever()
|
||||
}
|
||||
|
||||
@@ -614,6 +616,7 @@ fn run_terminal_gui(config: config::ConfigHandle, opts: StartCommand) -> anyhow:
|
||||
drop(activity);
|
||||
});
|
||||
|
||||
maybe_show_configuration_error_window();
|
||||
gui.run_forever()
|
||||
}
|
||||
|
||||
@@ -687,6 +690,13 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_show_configuration_error_window() {
|
||||
if let Err(err) = config::configuration_result() {
|
||||
let err = format!("{:#}", err);
|
||||
termwiztermtab::show_configuration_error_message(&err);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> anyhow::Result<()> {
|
||||
// This is a bit gross.
|
||||
// In order to not to automatically open a standard windows console when
|
||||
@@ -727,14 +737,7 @@ fn run() -> anyhow::Result<()> {
|
||||
if !opts.skip_config {
|
||||
config::reload();
|
||||
}
|
||||
let config = match config::configuration_result() {
|
||||
Err(err) => {
|
||||
let err = format!("{:#}", err);
|
||||
toast_notification("Wezterm configuration", &err);
|
||||
config::configuration()
|
||||
}
|
||||
Ok(config) => config,
|
||||
};
|
||||
let config = crate::config::configuration();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
|
||||
@@ -463,3 +463,34 @@ pub fn message_box_ok(message: &str) {
|
||||
}))
|
||||
.ok();
|
||||
}
|
||||
|
||||
/// If the GUI has been started, pops up a window with the supplied error
|
||||
/// message framed as a configuration error.
|
||||
/// If there is no GUI front end, generates a toast notification instead.
|
||||
/// This is a little bit lame in that it will open a new window for each error
|
||||
/// event rather than updating a prior window.
|
||||
pub fn show_configuration_error_message(err: &str) {
|
||||
log::error!("While (re)loading configuration: {}", err);
|
||||
if crate::frontend::has_gui_front_end() {
|
||||
let wrapped = textwrap::fill(&err, 78);
|
||||
let mut message = wrapped.replace("\n", "\r\n");
|
||||
message.push_str("\r\n\r\n");
|
||||
|
||||
promise::spawn::spawn_into_main_thread(run(80, 24, move |mut term| {
|
||||
term.render(&[
|
||||
Change::Title("Wezterm Configuration Error".to_string()),
|
||||
Change::Text(message.to_string()),
|
||||
])
|
||||
.map_err(Error::msg)?;
|
||||
|
||||
let mut editor = LineEditor::new(term);
|
||||
editor.set_prompt("(press enter to close this window)");
|
||||
|
||||
let mut host = NopLineEditorHost::default();
|
||||
editor.read_line(&mut host).ok();
|
||||
Ok(())
|
||||
}));
|
||||
} else {
|
||||
crate::toast_notification("Wezterm Configuration", &err);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user