From 950b8497999b1b626743317bf7149eadd5bfe6fd Mon Sep 17 00:00:00 2001 From: Rolo Date: Wed, 18 Dec 2024 00:26:09 -0800 Subject: [PATCH] refactor: reformat command prompt --- helix-term/src/commands/typed.rs | 45 ++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index fb4522ebfa35..6d6312aa0596 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -3426,13 +3426,48 @@ pub(super) fn command_mode(cx: &mut Context) { prompt.doc_fn = Box::new(|input: &str| { let shellwords = Shellwords::from(input); - if let Some(typed::TypableCommand { doc, aliases, .. }) = - typed::TYPABLE_COMMAND_MAP.get(shellwords.command()) + if let Some(typed::TypableCommand { + name, + aliases, + flags, + doc, + .. + }) = typed::TYPABLE_COMMAND_MAP.get(shellwords.command()) { - if aliases.is_empty() { - return Some((*doc).into()); + // EXAMPLE: + // write [] write the current buffer to its file. + // aliases: w + // flags: + // --no-format exclude formatting operation when saving. + let mut prompt = String::new(); + + prompt.push_str(name); + + if !flags.is_empty() { + prompt.push_str(" []"); } - return Some(format!("{}\nAliases: {}", doc, aliases.join(", ")).into()); + + writeln!(prompt, " - {doc}").unwrap(); + + if !aliases.is_empty() { + writeln!(prompt, "aliases: {}", aliases.join(", ")).unwrap(); + } + + if !flags.is_empty() { + prompt.push_str("flags:\n"); + + for flag in *flags { + write!(prompt, " --{}", flag.long).unwrap(); + + if let Some(short) = flag.short { + write!(prompt, ", -{short}").unwrap(); + } + + writeln!(prompt, " {}", flag.desc).unwrap(); + } + } + + return Some(prompt.into()); } None