1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Merge pull request #7881 from alexs-sh/7736-control-flow-experiments

uucore/echo:handle ControlFlow result
This commit is contained in:
Alexander 2025-05-05 00:33:51 +02:00 committed by GitHub
parent 13c0a813eb
commit 7d5cfbc4b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 6 deletions

View file

@ -9,7 +9,7 @@ use std::env;
use std::ffi::{OsStr, OsString};
use std::io::{self, StdoutLock, Write};
use uucore::error::{UResult, USimpleError};
use uucore::format::{EscapedChar, FormatChar, OctalParsing, parse_escape_only};
use uucore::format::{FormatChar, OctalParsing, parse_escape_only};
use uucore::{format_usage, help_about, help_section, help_usage};
const ABOUT: &str = help_about!("echo.md");
@ -191,10 +191,9 @@ fn execute(
if escaped {
for item in parse_escape_only(bytes, OctalParsing::ThreeDigits) {
match item {
EscapedChar::End => return Ok(()),
c => c.write(&mut *stdout_lock)?,
};
if item.write(&mut *stdout_lock)?.is_break() {
return Ok(());
}
}
} else {
stdout_lock.write_all(bytes)?;

View file

@ -283,7 +283,9 @@ fn printf_writer<'a>(
let args = args.into_iter().cloned().collect::<Vec<_>>();
let mut args = FormatArguments::new(&args);
for item in parse_spec_only(format_string.as_ref()) {
item?.write(&mut writer, &mut args)?;
if item?.write(&mut writer, &mut args)?.is_break() {
break;
}
}
Ok(())
}

View file

@ -762,3 +762,12 @@ fn test_uchild_when_run_no_wait_with_a_non_blocking_util() {
// we should be able to call wait without panics and apply some assertions
child.wait().unwrap().code_is(0).no_stdout().no_stderr();
}
#[test]
fn test_escape_sequence_ctrl_c() {
new_ucmd!()
.args(&["-e", "show\\c123"])
.run()
.success()
.stdout_only("show");
}