ALPHA: wire is a tool to deploy nixos systems wire.althaea.zone/
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix prompts not appearing on interactive commands

+62 -33
+60 -31
wire/lib/src/commands/interactive.rs
··· 442 442 .unwrap(); 443 443 444 444 let mut buffer = [0u8; 1024]; 445 - let mut stdout = std::io::stdout(); 445 + let mut stderr = std::io::stderr(); 446 446 let mut began = false; 447 447 let mut log_buffer = LogBuffer::new(); 448 + let mut raw_mode_buffer = Vec::new(); 448 449 449 450 'outer: loop { 450 451 match reader.read(&mut buffer) { 451 452 Ok(0) => break 'outer, 452 453 Ok(n) => { 454 + if !began { 455 + if handle_rawmode_data( 456 + &mut stderr, 457 + &buffer, 458 + n, 459 + &mut raw_mode_buffer, 460 + &aho_corasick, 461 + &began_tx, 462 + )? { 463 + began = true; 464 + } 465 + 466 + continue; 467 + } 468 + 453 469 log_buffer.process_slice(&buffer[..n]); 454 470 455 471 while let Some(mut line) = log_buffer.next_line() { ··· 458 474 .map(|x| x.pattern()) 459 475 .collect::<Vec<_>>(); 460 476 461 - if searched.iter().any(|x| x == &PatternID::must(0)) { 462 - debug!("start needle was found, switching mode..."); 463 - let _ = began_tx.send(()); 464 - began = true; 465 - continue; 466 - } 467 - 468 477 if searched.iter().any(|x| x == &PatternID::must(1)) { 469 478 debug!("succeed needle was found, marking child as succeeding."); 470 479 completion_status.mark_completed(true); ··· 477 486 break 'outer; 478 487 } 479 488 480 - if began { 481 - if line.starts_with(b"#") { 482 - let stripped = &mut line[1..]; 489 + if line.starts_with(b"#") { 490 + let stripped = &mut line[1..]; 483 491 484 - if log_stdout { 485 - output_mode.trace_slice(stripped); 486 - } 492 + if log_stdout { 493 + output_mode.trace_slice(stripped); 494 + } 487 495 488 - let mut queue = stdout_collection.lock().unwrap(); 489 - // clone 490 - queue.push_front(String::from_utf8_lossy(stripped).to_string()); 491 - continue; 492 - } 496 + let mut queue = stdout_collection.lock().unwrap(); 497 + queue.push_front(String::from_utf8_lossy(stripped).to_string()); 498 + continue; 499 + } 493 500 494 - let log = output_mode.trace_slice(&mut line); 501 + let log = output_mode.trace_slice(&mut line); 495 502 496 - if let Some(error_msg) = log { 497 - let mut queue = stderr_collection.lock().unwrap(); 503 + if let Some(error_msg) = log { 504 + let mut queue = stderr_collection.lock().unwrap(); 498 505 499 - // add at most 20 message to the front, drop the rest. 500 - queue.push_front(error_msg); 501 - queue.truncate(20); 502 - } 503 - } else { 504 - stdout 505 - .write_all(&line) 506 - .map_err(CommandError::WritingClientStdout)?; 507 - stdout.flush().map_err(CommandError::WritingClientStdout)?; 506 + // add at most 20 message to the front, drop the rest. 507 + queue.push_front(error_msg); 508 + queue.truncate(20); 508 509 } 509 510 } 510 511 } ··· 525 526 debug!("stdout: goodbye"); 526 527 527 528 Ok(()) 529 + } 530 + 531 + fn handle_rawmode_data( 532 + stderr: &mut std::io::Stderr, 533 + buffer: &[u8], 534 + n: usize, 535 + raw_mode_buffer: &mut Vec<u8>, 536 + aho_corasick: &AhoCorasick, 537 + began_tx: &Sender<()>, 538 + ) -> Result<bool, CommandError> { 539 + raw_mode_buffer.extend_from_slice(&buffer[..n]); 540 + 541 + if aho_corasick 542 + .find_iter(&raw_mode_buffer) 543 + .any(|x| x.pattern() == PatternID::must(0)) 544 + { 545 + println!("start needle was found, switching mode..."); 546 + let _ = began_tx.send(()); 547 + return Ok(true); 548 + } 549 + 550 + stderr 551 + .write_all(&buffer[..n]) 552 + .map_err(CommandError::WritingClientStderr)?; 553 + 554 + stderr.flush().map_err(CommandError::WritingClientStderr)?; 555 + 556 + Ok(false) 528 557 } 529 558 530 559 /// Exits on any data written to `cancel_pipe_r`
+2 -2
wire/lib/src/errors.rs
··· 224 224 code(wire::command::WritingClientStdout), 225 225 url("{DOCS_URL}#{}", self.code().unwrap()) 226 226 )] 227 - #[error("Failed to write to client stdout.")] 228 - WritingClientStdout(#[source] std::io::Error), 227 + #[error("Failed to write to client stderr.")] 228 + WritingClientStderr(#[source] std::io::Error), 229 229 230 230 #[diagnostic( 231 231 code(wire::command::WritingMasterStdin),