fix(core): skip vt100 parsing if tui disabled (#31010)

This commit is contained in:
Craigory Coppola 2025-05-02 14:35:03 -04:00 committed by GitHub
parent 7059d6f17b
commit 6e1f304898
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,42 +109,45 @@ impl PseudoTerminal {
let quiet = quiet_clone.load(Ordering::Relaxed); let quiet = quiet_clone.load(Ordering::Relaxed);
trace!("Quiet: {}", quiet); trace!("Quiet: {}", quiet);
debug!("Read {} bytes", len); debug!("Read {} bytes", len);
if let Ok(mut parser) = parser_clone.write() { if is_within_nx_tui {
parser.process(&buf[..len]); if let Ok(mut parser) = parser_clone.write() {
if is_within_nx_tui {
if !quiet { trace!("Processing data via vt100 for use in tui");
let mut logged_interrupted_error = false; parser.process(&buf[..len]);
let mut content = String::from_utf8_lossy(&buf[0..len]).to_string();
if content.contains("\x1B[6n") {
trace!(
"Prevented terminal escape sequence ESC[6n from being printed."
);
content = content.replace("\x1B[6n", "");
} }
}
}
let write_buf = content.as_bytes(); if !quiet {
debug!("Escaped Stdout: {:?}", write_buf.escape_ascii().to_string()); let mut logged_interrupted_error = false;
while let Err(e) = stdout.write_all(&write_buf) { let mut content = String::from_utf8_lossy(&buf[0..len]).to_string();
match e.kind() { if content.contains("\x1B[6n") {
std::io::ErrorKind::Interrupted => { trace!("Prevented terminal escape sequence ESC[6n from being printed.");
if !logged_interrupted_error { content = content.replace("\x1B[6n", "");
trace!("Interrupted error writing to stdout: {:?}", e); }
logged_interrupted_error = true;
} let write_buf = content.as_bytes();
continue; debug!("Escaped Stdout: {:?}", write_buf.escape_ascii().to_string());
}
_ => { while let Err(e) = stdout.write_all(&write_buf) {
// We should figure out what to do for more error types as they appear. match e.kind() {
trace!("Error writing to stdout: {:?}", e); std::io::ErrorKind::Interrupted => {
trace!("Error kind: {:?}", e.kind()); if !logged_interrupted_error {
break 'read_loop; trace!("Interrupted error writing to stdout: {:?}", e);
logged_interrupted_error = true;
} }
continue;
}
_ => {
// We should figure out what to do for more error types as they appear.
trace!("Error writing to stdout: {:?}", e);
trace!("Error kind: {:?}", e.kind());
break 'read_loop;
} }
} }
let _ = stdout.flush();
} }
let _ = stdout.flush();
} else { } else {
debug!("Failed to lock parser"); debug!("Failed to lock parser");
} }
@ -211,10 +214,13 @@ impl PseudoTerminal {
let command_info = format!("> {}\n\n\r", command_label.unwrap_or(command)); let command_info = format!("> {}\n\n\r", command_label.unwrap_or(command));
self.stdout_tx.send(command_info.clone()).ok(); self.stdout_tx.send(command_info.clone()).ok();
self.parser if self.is_within_nx_tui {
.write() self.parser
.expect("Failed to acquire parser write lock") .write()
.process(command_info.as_bytes()); .expect("Failed to acquire parser write lock")
.process(command_info.as_bytes());
}
trace!("Running {}", command_clone); trace!("Running {}", command_clone);
let mut child = pair.slave.spawn_command(cmd)?; let mut child = pair.slave.spawn_command(cmd)?;
self.running.store(true, Ordering::SeqCst); self.running.store(true, Ordering::SeqCst);