From 2a47bc0c7dd6238ce3416e19d2ba57f3a7626f64 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 18 Jul 2025 15:23:30 +0100 Subject: [PATCH] term: provide default HELP message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide a default message that informs the user of the `(e)`, `(enter)`, and `(esc)` functionality. Unfortunately, it is not possible to provide any message that is better customised to each case, due to `inquire` requiring a `'a` lifetime on all its inputs – this rules out providing any kind of `String` input. The first paramter of `Editor::new` can already be used to provide more contextual information. The second parameter is left configurable, but for now `Editor::HELP` is used everywhere. --- crates/radicle-cli/src/commands/config.rs | 13 +++++++------ crates/radicle-term/src/editor.rs | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/radicle-cli/src/commands/config.rs b/crates/radicle-cli/src/commands/config.rs index 402e5a46..33fe7033 100644 --- a/crates/radicle-cli/src/commands/config.rs +++ b/crates/radicle-cli/src/commands/config.rs @@ -188,15 +188,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { Operation::Edit => { let config = std::fs::read_to_string(&path)?; - match term::editor::Editor::new("Change configuration.", "You may change the Radicle configuration using your editor. Pressing (e) will open the editor. Save the file and exit the editor to submit your changes.") - .editor(term::editor::default_editor_command().as_ref()) - .extension(".json") - .initial(&config) - .edit()? { + match term::editor::Editor::new("Edit configuration", term::editor::Editor::HELP) + .editor(term::editor::default_editor_command().as_ref()) + .extension(".json") + .initial(&config) + .edit()? + { Some(edited) => { std::fs::write(&path, edited)?; term::success!("Successfully made changes to the configuration at {path:?}"); - }, + } None => { term::info!("No changes were made to the configuration at {path:?}") } diff --git a/crates/radicle-term/src/editor.rs b/crates/radicle-term/src/editor.rs index 9a1ba68c..de96e74c 100644 --- a/crates/radicle-term/src/editor.rs +++ b/crates/radicle-term/src/editor.rs @@ -12,10 +12,12 @@ pub struct Editor<'a>(pub inquire::Editor<'a>); #[error(transparent)] pub struct Error(#[from] InquireError); -impl Editor<'_> { +impl<'a> Editor<'a> { + pub const HELP: &'a str = "(e) to edit. (enter) to save and exit. (esc) to cancel and quit."; + /// Create a new editor for editing a comment. pub fn comment() -> Self { - Self::new("Enter comment.", "You may enter your comment using your editor. Pressing (e) will open the editor. Save the file and exit the editor to submit your comment.") + Self::new("Enter comment.", Self::HELP) } /// Open the editor and return the edited text.