From c05434ebd5a2335f432db9ac1820f3e4ba181e68 Mon Sep 17 00:00:00 2001 From: tippfehlr Date: Sun, 10 Dec 2023 00:01:41 +0100 Subject: [PATCH] cli: add emoji picker to `rad issue react` The help shows that `--emoji` is optional, however it was not. Instead of making `--emoji` mandatory, I added an emoji picker for the emojis featured in the web ui. `--emoji` is now (really) optional, but can be used to react with other emojis not included in the selector or the web ui. --- radicle-cli/src/commands/issue.rs | 9 +++++++-- radicle-cli/src/terminal/io.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index d15b8479..ed27284b 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -137,7 +137,7 @@ pub enum Operation { }, React { id: Rev, - reaction: Reaction, + reaction: Option, comment_id: Option, }, Assign { @@ -435,7 +435,7 @@ impl Args for Options { }, OperationName::React => Operation::React { id: id.ok_or_else(|| anyhow!("an issue must be provided"))?, - reaction: reaction.ok_or_else(|| anyhow!("a reaction emoji must be provided"))?, + reaction, comment_id, }, OperationName::Delete => Operation::Delete { @@ -595,6 +595,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { Some(cid) => cid, None => *term::io::comment_select(&issue).map(|(cid, _)| cid)?, }; + let reaction = match reaction { + Some(reaction) => reaction, + None => term::io::reaction_select()?, + }; + // SAFETY: reaction is never None here. issue.react(comment_id, reaction, true, &signer)?; } } diff --git a/radicle-cli/src/terminal/io.rs b/radicle-cli/src/terminal/io.rs index 334e62f3..9b1f6dd6 100644 --- a/radicle-cli/src/terminal/io.rs +++ b/radicle-cli/src/terminal/io.rs @@ -1,6 +1,7 @@ use anyhow::anyhow; use radicle::cob::issue::Issue; use radicle::cob::thread::{Comment, CommentId}; +use radicle::cob::Reaction; use radicle::crypto::ssh::keystore::MemorySigner; use radicle::crypto::{ssh::Keystore, Signer}; use radicle::profile::env::RAD_PASSPHRASE; @@ -79,3 +80,13 @@ pub fn comment_select(issue: &Issue) -> anyhow::Result<(&CommentId, &Comment)> { .copied() .ok_or(anyhow!("failed to perform comment selection")) } + +pub fn reaction_select() -> anyhow::Result { + let emoji = Select::new( + "With which emoji do you want to react?", + vec!['🐙', '👾', '💯', '✨', '🙇', '🙅', '❤'], + ) + .with_render_config(*CONFIG) + .prompt()?; + Ok(Reaction::new(emoji)?) +}