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);
trace!("Quiet: {}", quiet);
debug!("Read {} bytes", len);
if let Ok(mut parser) = parser_clone.write() {
parser.process(&buf[..len]);
if !quiet {
let mut logged_interrupted_error = false;
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", "");
if is_within_nx_tui {
if let Ok(mut parser) = parser_clone.write() {
if is_within_nx_tui {
trace!("Processing data via vt100 for use in tui");
parser.process(&buf[..len]);
}
}
}
let write_buf = content.as_bytes();
debug!("Escaped Stdout: {:?}", write_buf.escape_ascii().to_string());
if !quiet {
let mut logged_interrupted_error = false;
while let Err(e) = stdout.write_all(&write_buf) {
match e.kind() {
std::io::ErrorKind::Interrupted => {
if !logged_interrupted_error {
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 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();
debug!("Escaped Stdout: {:?}", write_buf.escape_ascii().to_string());
while let Err(e) = stdout.write_all(&write_buf) {
match e.kind() {
std::io::ErrorKind::Interrupted => {
if !logged_interrupted_error {
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 {
debug!("Failed to lock parser");
}
@ -211,10 +214,13 @@ impl PseudoTerminal {
let command_info = format!("> {}\n\n\r", command_label.unwrap_or(command));
self.stdout_tx.send(command_info.clone()).ok();
self.parser
.write()
.expect("Failed to acquire parser write lock")
.process(command_info.as_bytes());
if self.is_within_nx_tui {
self.parser
.write()
.expect("Failed to acquire parser write lock")
.process(command_info.as_bytes());
}
trace!("Running {}", command_clone);
let mut child = pair.slave.spawn_command(cmd)?;
self.running.store(true, Ordering::SeqCst);