diff --git a/crates/nu-command/src/platform/input/input_.rs b/crates/nu-command/src/platform/input/input_.rs index 54e6f575c6..d6aadf576b 100644 --- a/crates/nu-command/src/platform/input/input_.rs +++ b/crates/nu-command/src/platform/input/input_.rs @@ -5,6 +5,7 @@ use crossterm::{ style::Print, terminal::{self, ClearType}, }; +use itertools::Itertools; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; @@ -40,9 +41,9 @@ impl Command for Input { .allow_variants_without_examples(true) .optional("prompt", SyntaxShape::String, "prompt to show the user") .named( - "bytes-until", + "bytes-until-any", SyntaxShape::String, - "read bytes (not text) until a stop byte", + "read bytes (not text) until any of the given stop bytes is seen", Some('u'), ) .named( @@ -63,7 +64,7 @@ impl Command for Input { _input: PipelineData, ) -> Result { let prompt: Option = call.opt(engine_state, stack, 0)?; - let bytes_until: Option = call.get_flag(engine_state, stack, "bytes-until")?; + let bytes_until: Option = call.get_flag(engine_state, stack, "bytes-until-any")?; let suppress_output = call.has_flag("suppress-output"); let numchar: Option> = call.get_flag(engine_state, stack, "numchar")?; let numchar: Spanned = numchar.unwrap_or(Spanned { @@ -80,19 +81,6 @@ impl Command for Input { )); } - let byte_until = if let Some(bytes_until) = bytes_until { - if let Some(c) = bytes_until.bytes().next() { - Some(c) - } else { - let _ = crossterm::terminal::disable_raw_mode(); - return Err(ShellError::IOError( - "input can't stop on this byte".to_string(), - )); - } - } else { - None - }; - if let Some(prompt) = &prompt { print!("{prompt}"); let _ = std::io::stdout().flush(); @@ -127,8 +115,8 @@ impl Command for Input { continue; } - if let Some(byte_until) = byte_until { - if c == byte_until as char { + if let Some(bytes_until) = bytes_until.as_ref() { + if bytes_until.bytes().contains(&(c as u8)) { break; } }