1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-01-27 15:26:50 -05:00

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`.
This commit is contained in:
Andrew Borg (Kashin) 2025-01-16 15:04:21 +00:00 committed by GitHub
parent c9c41e637a
commit 5e78d20c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 41 additions and 23 deletions

View file

@ -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(),
}
}

View file

@ -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.

View file

@ -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,

View file

@ -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);

View file

@ -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(),

View file

@ -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,
)?;

View file

@ -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

View file

@ -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;
}

View file

@ -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>,