diff options
author | Andrew Borg (Kashin) <1192958+aborg-dev@users.noreply.github.com> | 2025-01-16 15:04:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-16 15:04:21 +0000 |
commit | 5e78d20c709cb1ab8d44ca7a8702cc26d779227c (patch) | |
tree | f5174dfb36771fbfb149b338f000ab27c119baab | |
parent | c9c41e637ac49f3cd67cf0362c596ae9d947f896 (diff) | |
download | r-alacritty-5e78d20c709cb1ab8d44ca7a8702cc26d779227c.tar.gz r-alacritty-5e78d20c709cb1ab8d44ca7a8702cc26d779227c.tar.bz2 r-alacritty-5e78d20c709cb1ab8d44ca7a8702cc26d779227c.zip |
Add option to drain PTY on shutdown
This patch removes the `hold` option on `alacritty_terminal` in favor of
a `drain_on_exit` option, which will drain the PTY before shutdown. The
hold logic is instead handled in `alacritty`.
-rw-r--r-- | alacritty/src/cli.rs | 4 | ||||
-rw-r--r-- | alacritty/src/config/ui_config.rs | 2 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 10 | ||||
-rw-r--r-- | alacritty/src/event.rs | 18 | ||||
-rw-r--r-- | alacritty/src/input/mod.rs | 5 | ||||
-rw-r--r-- | alacritty/src/window_context.rs | 2 | ||||
-rw-r--r-- | alacritty_terminal/CHANGELOG.md | 6 | ||||
-rw-r--r-- | alacritty_terminal/src/event_loop.rs | 13 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/mod.rs | 4 |
9 files changed, 41 insertions, 23 deletions
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index 5010ffc8..feac41bd 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -189,7 +189,7 @@ impl TerminalOptions { pty_config.shell = Some(command.into()); } - pty_config.hold |= self.hold; + pty_config.drain_on_exit |= self.hold; } } @@ -198,7 +198,7 @@ impl From<TerminalOptions> for PtyOptions { PtyOptions { working_directory: options.working_directory.take(), shell: options.command().map(Into::into), - hold: options.hold, + drain_on_exit: options.hold, env: HashMap::new(), } } diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index b44bda0d..53310090 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -130,7 +130,7 @@ impl UiConfig { let shell = self.terminal.shell.clone().or_else(|| self.shell.clone()).map(Into::into); let working_directory = self.working_directory.clone().or_else(|| self.general.working_directory.clone()); - PtyOptions { working_directory, shell, hold: false, env: HashMap::new() } + PtyOptions { working_directory, shell, drain_on_exit: false, env: HashMap::new() } } /// Generate key bindings for all keyboard hints. diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index fe40fab5..f9fb9272 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -109,6 +109,9 @@ pub struct Window { /// Flag indicating whether redraw was requested. pub requested_redraw: bool, + /// Hold the window when terminal exits. + pub hold: bool, + window: WinitWindow, /// Current window title. @@ -127,7 +130,7 @@ impl Window { event_loop: &ActiveEventLoop, config: &UiConfig, identity: &Identity, - _options: &mut WindowOptions, + options: &mut WindowOptions, #[rustfmt::skip] #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] x11_visual: Option<X11VisualInfo>, @@ -139,7 +142,7 @@ impl Window { #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] x11_visual, #[cfg(target_os = "macos")] - &_options.window_tabbing_id.take(), + &options.window_tabbing_id.take(), ); if let Some(position) = config.window.position { @@ -148,7 +151,7 @@ impl Window { } #[cfg(not(any(target_os = "macos", windows)))] - if let Some(token) = _options + if let Some(token) = options .activation_token .take() .map(ActivationToken::from_raw) @@ -199,6 +202,7 @@ impl Window { let is_x11 = matches!(window.window_handle().unwrap().as_raw(), RawWindowHandle::Xlib(_)); Ok(Self { + hold: options.terminal_options.hold, requested_redraw: false, title: identity.title, current_mouse_cursor, diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 2ac6279d..888bec4f 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -4,6 +4,7 @@ use crate::ConfigMonitor; use glutin::config::GetGlConfig; use std::borrow::Cow; use std::cmp::min; +use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet, VecDeque}; use std::error::Error; use std::ffi::OsStr; @@ -380,9 +381,14 @@ impl ApplicationHandler<Event> for Processor { }, (EventType::Terminal(TerminalEvent::Exit), Some(window_id)) => { // Remove the closed terminal. - let window_context = match self.windows.remove(window_id) { - Some(window_context) => window_context, - None => return, + let window_context = match self.windows.entry(*window_id) { + // Don't exit when terminal exits if user asked to hold the window. + Entry::Occupied(window_context) + if !window_context.get().display.window.hold => + { + window_context.remove() + }, + _ => return, }; // Unschedule pending events. @@ -1793,7 +1799,11 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> { }, WinitEvent::WindowEvent { event, .. } => { match event { - WindowEvent::CloseRequested => self.ctx.terminal.exit(), + WindowEvent::CloseRequested => { + // User asked to close the window, so no need to hold it. + self.ctx.window().hold = false; + self.ctx.terminal.exit(); + }, WindowEvent::ScaleFactorChanged { scale_factor, .. } => { let old_scale_factor = mem::replace(&mut self.ctx.window().scale_factor, scale_factor); diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 60a50529..3f85512f 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -324,7 +324,10 @@ impl<T: EventListener> Execute<T> for Action { #[cfg(not(target_os = "macos"))] Action::Hide => ctx.window().set_visible(false), Action::Minimize => ctx.window().set_minimized(true), - Action::Quit => ctx.terminal_mut().exit(), + Action::Quit => { + ctx.window().hold = false; + ctx.terminal_mut().exit(); + }, Action::IncreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP), Action::DecreaseFontSize => ctx.change_font_size(-FONT_SIZE_STEP), Action::ResetFontSize => ctx.reset_font_size(), diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index e3c39382..a0e66cc0 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -212,7 +212,7 @@ impl WindowContext { Arc::clone(&terminal), event_proxy.clone(), pty, - pty_config.hold, + pty_config.drain_on_exit, config.debug.ref_test, )?; diff --git a/alacritty_terminal/CHANGELOG.md b/alacritty_terminal/CHANGELOG.md index 55c21d3f..1b4824fb 100644 --- a/alacritty_terminal/CHANGELOG.md +++ b/alacritty_terminal/CHANGELOG.md @@ -8,7 +8,11 @@ sections should follow the order `Added`, `Changed`, `Deprecated`, `Fixed` and The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## 0.24.3-dev +## 0.25.0-dev + +### Changed + +- Replaced `Options::hold` with `Options::drain_on_exit` that drains, but doesn't hold, since holding can be done outside of alacritty_terminal ## 0.24.2 diff --git a/alacritty_terminal/src/event_loop.rs b/alacritty_terminal/src/event_loop.rs index 2b78f853..1bef1d4f 100644 --- a/alacritty_terminal/src/event_loop.rs +++ b/alacritty_terminal/src/event_loop.rs @@ -50,7 +50,7 @@ pub struct EventLoop<T: tty::EventedPty, U: EventListener> { tx: Sender<Msg>, terminal: Arc<FairMutex<Term<U>>>, event_proxy: U, - hold: bool, + drain_on_exit: bool, ref_test: bool, } @@ -64,7 +64,7 @@ where terminal: Arc<FairMutex<Term<U>>>, event_proxy: U, pty: T, - hold: bool, + drain_on_exit: bool, ref_test: bool, ) -> io::Result<EventLoop<T, U>> { let (tx, rx) = mpsc::channel(); @@ -76,7 +76,7 @@ where rx: PeekableReceiver::new(rx), terminal, event_proxy, - hold, + drain_on_exit, ref_test, }) } @@ -261,13 +261,10 @@ where if let Some(code) = code { self.event_proxy.send_event(Event::ChildExit(code)); } - if self.hold { - // With hold enabled, make sure the PTY is drained. + if self.drain_on_exit { let _ = self.pty_read(&mut state, &mut buf, pipe.as_mut()); - } else { - // Without hold, shutdown the terminal. - self.terminal.lock().exit(); } + self.terminal.lock().exit(); self.event_proxy.send_event(Event::Wakeup); break 'event_loop; } diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs index eed2a76d..208547ba 100644 --- a/alacritty_terminal/src/tty/mod.rs +++ b/alacritty_terminal/src/tty/mod.rs @@ -28,8 +28,8 @@ pub struct Options { /// Shell startup directory. pub working_directory: Option<PathBuf>, - /// Remain open after child process exits. - pub hold: bool, + /// Drain the child process output before exiting the terminal. + pub drain_on_exit: bool, /// Extra environment variables. pub env: HashMap<String, String>, |