Skip to content
Merged
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
74 changes: 40 additions & 34 deletions packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

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;
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", "");
}

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");
}
Expand Down Expand Up @@ -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);
Expand Down
Loading