helper: strip ANSI escape sequences at beginning of PTY start

This commit is contained in:
hinto.janai 2023-12-25 09:45:55 -05:00
parent 43e2e1b8a1
commit 864e8ea394
No known key found for this signature in database
GPG key ID: D47CE05FA175A499

View file

@ -271,6 +271,18 @@ impl Helper {
fn read_pty_xmrig(output_parse: Arc<Mutex<String>>, output_pub: Arc<Mutex<String>>, reader: Box<dyn std::io::Read + Send>) {
use std::io::BufRead;
let mut stdout = std::io::BufReader::new(reader).lines();
// Run a ANSI escape sequence filter for the first few lines.
for (i, line) in stdout.next().enumerate() {
let Some(Ok(line)) = line else { continue; }
let line = strip_ansi_escapes::strip_str(line);
if let Err(e) = writeln!(lock!(output_parse), "{}", line) { error!("XMRig PTY Parse | Output error: {}", e); }
if let Err(e) = writeln!(lock!(output_pub), "{}", line) { error!("XMRig PTY Pub | Output error: {}", e); }
if i > 20 {
break;
}
}
while let Some(Ok(line)) = stdout.next() {
// println!("{}", line); // For debugging.
if let Err(e) = writeln!(lock!(output_parse), "{}", line) { error!("XMRig PTY Parse | Output error: {}", e); }
@ -281,6 +293,18 @@ impl Helper {
fn read_pty_p2pool(output_parse: Arc<Mutex<String>>, output_pub: Arc<Mutex<String>>, reader: Box<dyn std::io::Read + Send>, gupax_p2pool_api: Arc<Mutex<GupaxP2poolApi>>) {
use std::io::BufRead;
let mut stdout = std::io::BufReader::new(reader).lines();
// Run a ANSI escape sequence filter for the first few lines.
for (i, line) in stdout.next().enumerate() {
let Some(Ok(line)) = line else { continue; }
let line = strip_ansi_escapes::strip_str(line);
if let Err(e) = writeln!(lock!(output_parse), "{}", line) { error!("P2Pool PTY Parse | Output error: {}", e); }
if let Err(e) = writeln!(lock!(output_pub), "{}", line) { error!("P2Pool PTY Pub | Output error: {}", e); }
if i > 20 {
break;
}
}
while let Some(Ok(line)) = stdout.next() {
// println!("{}", line); // For debugging.
if P2POOL_REGEX.payout.is_match(&line) {