Skip to content
Merged
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: 13 additions & 8 deletions cmux-tui/crates/cmux-tui/src/pipe_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::io::{BufRead, Write};
use std::path::Path;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, SyncSender};
use std::time::{Duration, Instant};

use base64::Engine as _;
use cmux_tui_core::SurfaceId;
Expand All @@ -46,6 +47,7 @@ const EVENT_QUEUE_CAPACITY: usize = 4096;
/// reset plus erase-scrollback, so the replacement replay does not stack on
/// top of the embedder's previous terminal state.
const REPLAY_RESET: &[u8] = b"\x1bc\x1b[3J";
const DAEMON_LOSS_PROBE_TIMEOUT: Duration = Duration::from_millis(500);

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PipeIoExitReason {
Expand Down Expand Up @@ -160,14 +162,17 @@ fn classify_daemon_loss(
socket_path: &Path,
terminal: &TerminalPublicId,
) -> PipeIoExitReason {
let terminal_still_exists =
remote.refresh_tree().ok().map(|tree| tree.resolve_terminal(terminal).is_some()).or_else(
|| {
let probe = RemoteSession::connect_for_terminal_attach(socket_path).ok()?;
let tree = probe.refresh_tree().ok()?;
Some(tree.resolve_terminal(terminal).is_some())
},
);
let deadline = Instant::now() + DAEMON_LOSS_PROBE_TIMEOUT;
let terminal_still_exists = remote
.refresh_tree_until(deadline)
.ok()
.map(|tree| tree.resolve_terminal(terminal).is_some())
.or_else(|| {
let probe =
RemoteSession::connect_for_terminal_attach_until(socket_path, deadline).ok()?;
let tree = probe.refresh_tree_until(deadline).ok()?;
Some(tree.resolve_terminal(terminal).is_some())
});
match terminal_still_exists {
Some(false) => PipeIoExitReason::TerminalEnded,
Some(true) | None => PipeIoExitReason::DaemonLost,
Expand Down
Loading
Loading