term: provide default HELP message
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.
This commit is contained in:
parent
a998ce691d
commit
2a47bc0c7d
|
|
@ -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.")
|
||||
match term::editor::Editor::new("Edit configuration", term::editor::Editor::HELP)
|
||||
.editor(term::editor::default_editor_command().as_ref())
|
||||
.extension(".json")
|
||||
.initial(&config)
|
||||
.edit()? {
|
||||
.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:?}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue