From 9159cbd4a3ea61ac78c70dbe0b9899be350b6077 Mon Sep 17 00:00:00 2001 From: William Etheredge Date: Sat, 1 Oct 2022 12:32:12 -0500 Subject: [PATCH] Replace Debug formatting with minimal escaping --- helix-term/src/commands/typed.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 7cb90d32a5db5..a356803433de7 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -990,9 +990,20 @@ fn get_character_info( } let grapheme = text.slice(grapheme_start..grapheme_end).to_string(); - let encoding = doc.encoding(); + let printable = grapheme.chars().fold(String::new(), |mut s, c| { + match c { + '\0' => s.push_str("\\0"), + '\t' => s.push_str("\\t"), + '\n' => s.push_str("\\n"), + '\r' => s.push_str("\\r"), + _ => s.push(c), + } + + s + }); + // Convert to Unicode codepoints if in UTF-8 let unicode = if encoding == encoding::UTF_8 { let mut unicode = " (".to_owned(); @@ -1080,7 +1091,7 @@ fn get_character_info( }; cx.editor - .set_status(format!("{grapheme:?}{unicode}{dec} Hex{hex}")); + .set_status(format!("\"{printable}\"{unicode}{dec} Hex{hex}")); Ok(()) }