Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions app/src/terminal/local_tty/terminal_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,23 @@ fn on_shell_determined<S: TerminalSurface>(
});

// Create the channel above and pass the receving side to the event loop.
let event_loop_handle = TerminalManager::<S>::start_pty_event_loop(
let event_loop_handle = match TerminalManager::<S>::start_pty_event_loop(
pty,
event_loop_rx,
model.clone(),
channel_event_proxy,
);
) {
Ok(event_loop_handle) => event_loop_handle,
Err(err) => {
let err = anyhow::Error::new(err).context("Failed to create PTY event loop");
report_error!(&err);
manager.view.update(ctx, |surface, ctx| {
surface.on_pty_spawn_failed(err, ctx);
});
manager.model().lock().exit(ExitReason::PtySpawnFailed);
return;
}
};

manager.event_loop_handle = Some(event_loop_handle);
#[cfg(feature = "integration_tests")]
Expand Down Expand Up @@ -887,13 +898,13 @@ impl<S> TerminalManager<S> {
rx: mio_channel::Receiver<Message>,
model: Arc<FairMutex<TerminalModel>>,
channel_event_proxy: ChannelEventListener,
) -> JoinHandle<()> {
) -> std::io::Result<JoinHandle<()>> {
// Create the event loop and get a handle to the injector.
let event_loop = EventLoop::new(model, channel_event_proxy, pty, rx);
let event_loop = EventLoop::new(model, channel_event_proxy, pty, rx)?;

// Spawn the event loop on a separate thread to interact with the PTY and write the data back
// to the terminal.
event_loop.spawn()
Ok(event_loop.spawn())
}
}

Expand Down
18 changes: 14 additions & 4 deletions crates/warp_terminal/src/local_tty/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,24 @@ where
event_listener: ChannelEventListener,
pty: P,
rx: Receiver<Message>,
) -> EventLoop<P, M> {
EventLoop {
poll: mio::Poll::new().expect("create mio Poll"),
) -> io::Result<EventLoop<P, M>> {
let poll = match mio::Poll::new() {
Ok(poll) => poll,
Err(err) => {
if let Err(kill_err) = pty.kill() {
log::warn!("Failed to kill PTY after event loop creation failed: {kill_err:#}");
}
return Err(err);
}
};

Ok(EventLoop {
poll,
pty,
rx,
terminal,
event_listener,
}
})
}

/// Drain the channel.
Expand Down
Loading