Skip to content

Commit 7d5cfbc

Browse files
authored
Merge pull request #7881 from alexs-sh/7736-control-flow-experiments
uucore/echo:handle ControlFlow result
1 parent 13c0a81 commit 7d5cfbc

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/uu/echo/src/echo.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::env;
99
use std::ffi::{OsStr, OsString};
1010
use std::io::{self, StdoutLock, Write};
1111
use uucore::error::{UResult, USimpleError};
12-
use uucore::format::{EscapedChar, FormatChar, OctalParsing, parse_escape_only};
12+
use uucore::format::{FormatChar, OctalParsing, parse_escape_only};
1313
use uucore::{format_usage, help_about, help_section, help_usage};
1414

1515
const ABOUT: &str = help_about!("echo.md");
@@ -191,10 +191,9 @@ fn execute(
191191

192192
if escaped {
193193
for item in parse_escape_only(bytes, OctalParsing::ThreeDigits) {
194-
match item {
195-
EscapedChar::End => return Ok(()),
196-
c => c.write(&mut *stdout_lock)?,
197-
};
194+
if item.write(&mut *stdout_lock)?.is_break() {
195+
return Ok(());
196+
}
198197
}
199198
} else {
200199
stdout_lock.write_all(bytes)?;

src/uucore/src/lib/features/format/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ fn printf_writer<'a>(
283283
let args = args.into_iter().cloned().collect::<Vec<_>>();
284284
let mut args = FormatArguments::new(&args);
285285
for item in parse_spec_only(format_string.as_ref()) {
286-
item?.write(&mut writer, &mut args)?;
286+
if item?.write(&mut writer, &mut args)?.is_break() {
287+
break;
288+
}
287289
}
288290
Ok(())
289291
}

tests/by-util/test_echo.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,12 @@ fn test_uchild_when_run_no_wait_with_a_non_blocking_util() {
762762
// we should be able to call wait without panics and apply some assertions
763763
child.wait().unwrap().code_is(0).no_stdout().no_stderr();
764764
}
765+
766+
#[test]
767+
fn test_escape_sequence_ctrl_c() {
768+
new_ucmd!()
769+
.args(&["-e", "show\\c123"])
770+
.run()
771+
.success()
772+
.stdout_only("show");
773+
}

0 commit comments

Comments
 (0)