From 39f03bf5e426bacbf9e059dc08837941d09bf6cf Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 27 Dec 2021 00:11:08 +0100 Subject: [PATCH] Decode escaped newlines in history command (#592) Reedline currently encodes newlines as `<\n>` --- crates/nu-command/src/core_commands/history.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/core_commands/history.rs b/crates/nu-command/src/core_commands/history.rs index 6593840674..fcff71f51b 100644 --- a/crates/nu-command/src/core_commands/history.rs +++ b/crates/nu-command/src/core_commands/history.rs @@ -4,6 +4,12 @@ use nu_protocol::{ Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, }; +const NEWLINE_ESCAPE_CODE: &str = "<\\n>"; + +fn decode_newlines(escaped: &str) -> String { + escaped.replace(NEWLINE_ESCAPE_CODE, "\n") +} + #[derive(Clone)] pub struct History; @@ -48,7 +54,7 @@ impl Command for History { Ok(contents .lines() .map(move |x| Value::String { - val: x.to_string(), + val: decode_newlines(x), span: head, }) .collect::>()