wezterm: closing a window now prompts for confirmation by default

Adds `window_close_confirmation = "AlwaysPrompt"` as the default
configuration.  Can be set to `NeverPrompt` to disable prompting.
This commit is contained in:
Wez Furlong committed 2020-12-23 09:58:38 -08:00
1 parent 2c18a408c3
commit 5787bdff53
6 files changed
+100 -11

No files matched your search

+18
View File
@@ -834,6 +834,9 @@ pub struct Config {
/// mapping annoying in vim :-p
#[serde(default)]
pub enable_csi_u_key_encoding: bool,
#[serde(default)]
pub window_close_confirmation: WindowCloseConfirmation,
}
fn default_one_point_oh_f64() -> f64 {
@@ -906,6 +909,21 @@ pub struct WindowPadding {
}
impl_lua_conversion!(WindowPadding);
#[derive(Deserialize, Serialize, Clone, Copy, Debug)]
pub enum WindowCloseConfirmation {
AlwaysPrompt,
NeverPrompt,
// TODO: something smart where we see whether the
// running programs are stateful
}
impl_lua_conversion!(WindowCloseConfirmation);
impl Default for WindowCloseConfirmation {
fn default() -> Self {
WindowCloseConfirmation::AlwaysPrompt
}
}
impl Default for Config {
fn default() -> Self {
// Ask serde to provide the defaults based on the attributes
+1
View File
@@ -30,6 +30,7 @@ brief notes about them may accumulate here.
* The 256 color cube now uses slightly brighter colors [#348](https://github.com/wez/wezterm/issues/348)
* New: added `line_height` configuration option to scale the computed cell height. The default is `1.0`, resulting in using the font-specified metrics. Setting it to `1.2` will result in a 20% larger cell height.
* macOS: Fixed an issue where hovering over the split between panes could result in wezterm becoming unresponsive [#391](https://github.com/wez/wezterm/issues/391)
* Closing windows will now prompt for confirmation before proceeding with the close. Added `window_close_confirmation` to control this; valid values are `AlwaysPrompt` and `NeverPrompt`. [#280](https://github.com/wez/wezterm/issues/280)
### 20201101-103216-403d002d
+4
View File
@@ -61,6 +61,10 @@ return {
-- Specifies the maximum width that a tab can have in the
-- tab bar. Defaults to 16 glyphs in width.
tab_max_width = 16,
-- Set this to "NeverPrompt" if you don't like confirming closing
-- windows every time
window_close_confirmation = "AlwaysPrompt",
}
```
@@ -109,3 +109,53 @@ pub fn confirm_close_tab(
Ok(())
}
pub fn confirm_close_window(
mut term: TermWizTerminal,
mux_window_id: WindowId,
) -> anyhow::Result<()> {
term.set_raw_mode()?;
let changes = vec![
Change::ClearScreen(ColorAttribute::Default),
Change::CursorPosition {
x: Position::Absolute(0),
y: Position::Absolute(0),
},
Change::Text(
"Really kill this window and all contained tabs and panes? [y/n]\r\n".to_string(),
),
];
term.render(&changes)?;
term.flush()?;
while let Ok(Some(event)) = term.poll_input(None) {
match event {
InputEvent::Key(KeyEvent {
key: KeyCode::Char('y'),
..
}) => {
promise::spawn::spawn_into_main_thread(async move {
let mux = Mux::get().unwrap();
mux.kill_window(mux_window_id);
})
.detach();
break;
}
InputEvent::Key(KeyEvent {
key: KeyCode::Char('n'),
..
})
| InputEvent::Key(KeyEvent {
key: KeyCode::Escape,
..
}) => {
break;
}
_ => {}
}
}
Ok(())
}
+1
View File
@@ -13,6 +13,7 @@ mod tabnavigator;
pub use confirm_close_pane::confirm_close_pane;
pub use confirm_close_pane::confirm_close_tab;
pub use confirm_close_pane::confirm_close_window;
pub use copy::CopyOverlay;
pub use launcher::launcher;
pub use search::SearchOverlay;
+26 -11
View File
@@ -3,8 +3,8 @@ use super::quad::*;
use super::renderstate::*;
use super::utilsprites::RenderMetrics;
use crate::gui::overlay::{
confirm_close_pane, confirm_close_tab, launcher, start_overlay, start_overlay_pane,
tab_navigator, CopyOverlay, SearchOverlay,
confirm_close_pane, confirm_close_tab, confirm_close_window, launcher, start_overlay,
start_overlay_pane, tab_navigator, CopyOverlay, SearchOverlay,
};
use crate::gui::scrollbar::*;
use crate::gui::selection::*;
@@ -27,7 +27,7 @@ use anyhow::{anyhow, bail, ensure};
use config::keyassignment::{
InputMap, KeyAssignment, MouseEventTrigger, SpawnCommand, SpawnTabDomain,
};
use config::{configuration, ConfigHandle};
use config::{configuration, ConfigHandle, WindowCloseConfirmation};
use lru::LruCache;
use mux::activity::Activity;
use mux::domain::{DomainId, DomainState};
@@ -272,16 +272,31 @@ impl WindowCallbacks for TermWindow {
fn can_close(&mut self) -> bool {
let mux = Mux::get().unwrap();
let tab_ids: Vec<TabId> = if let Some(win) = mux.get_window(self.mux_window_id) {
win.iter().map(|tab| tab.tab_id()).collect()
} else {
return true;
};
let config = configuration();
match config.window_close_confirmation {
WindowCloseConfirmation::NeverPrompt => {
// Immediately kill the tabs and allow the window to close
mux.kill_window(self.mux_window_id);
true
}
WindowCloseConfirmation::AlwaysPrompt => {
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
Some(tab) => tab,
None => return true,
};
for id in tab_ids {
mux.remove_tab(id);
let mux_window_id = self.mux_window_id;
let (overlay, future) = start_overlay(self, &tab, move |_tab_id, term| {
confirm_close_window(term, mux_window_id)
});
self.assign_overlay(tab.tab_id(), overlay);
promise::spawn::spawn(future).detach();
// Don't close right now; let the close happen from
// the confirmation overlay
false
}
}
true
}
fn as_any(&mut self) -> &mut dyn Any {