Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Selection interfaces return multiple ids
Erik Kundt committed 2 years ago
commit b230a33f6fcd99bee9416dd9e1bc0dc28b216b0d
parent 91210160c4243a46aafa4ef5785044e358a29c93
4 files changed +53 -75
modified bin/commands/issue/select/event.rs
@@ -67,7 +67,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IdSelect> {
            Event::Keyboard(KeyEvent {
                code: Key::Enter, ..
            }) => submit().map(|id| {
-
                let output = SelectionExit::new(None, IssueId::from(id));
+
                let output = SelectionExit::default().with_id(IssueId::from(id));
                Message::Quit(Some(output))
            }),
            _ => None,
@@ -110,40 +110,36 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<OperationSelect> {
            Event::Keyboard(KeyEvent {
                code: Key::Enter, ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", IssueOperation::Show)),
-
                    IssueId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", IssueOperation::Show))
+
                    .with_id(IssueId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('d'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", IssueOperation::Delete)),
-
                    IssueId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", IssueOperation::Delete))
+
                    .with_id(IssueId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('e'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", IssueOperation::Edit)),
-
                    IssueId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", IssueOperation::Edit))
+
                    .with_id(IssueId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('m'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", IssueOperation::Comment)),
-
                    IssueId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", IssueOperation::Comment))
+
                    .with_id(IssueId::from(id));
                Message::Quit(Some(exit))
            }),
            _ => None,
modified bin/commands/patch/select.rs
@@ -26,35 +26,8 @@ use tui::{Exit, PageStack, SelectionExit, Tui};

use page::ListView;

-
/// Wrapper around radicle's `PatchId` that serializes
-
/// to a human-readable string.
-
// #[derive(Clone, Debug, Eq, PartialEq)]
-
// pub struct PatchId(radicle::cob::patch::PatchId);
-

-
// impl From<radicle::cob::patch::PatchId> for PatchId {
-
//     fn from(value: radicle::cob::patch::PatchId) -> Self {
-
//         PatchId(value)
-
//     }
-
// }
-

-
// impl Display for PatchId {
-
//     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-
//         write!(f, "{}", self.0)
-
//     }
-
// }
-

-
// impl Serialize for PatchId {
-
//     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
-
//     where
-
//         S: Serializer,
-
//     {
-
//         serializer.serialize_str(&format!("{}", *self.0))
-
//     }
-
// }
-

-
/// The application's subject. It tells the application
+
/// The application's mode. It tells the application
/// which widgets to render and which output to produce.
-
///
/// Depends on CLI arguments given by the user.
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub enum Mode {
modified bin/commands/patch/select/event.rs
@@ -67,7 +67,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IdSelect> {
            Event::Keyboard(KeyEvent {
                code: Key::Enter, ..
            }) => submit().map(|id| {
-
                let output = SelectionExit::new(None, PatchId::from(id));
+
                let output = SelectionExit::default().with_id(PatchId::from(id));
                Message::Quit(Some(output))
            }),
            _ => None,
@@ -110,50 +110,45 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<OperationSelect> {
            Event::Keyboard(KeyEvent {
                code: Key::Enter, ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", PatchOperation::Show)),
-
                    PatchId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", PatchOperation::Show))
+
                    .with_id(PatchId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('c'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", PatchOperation::Checkout)),
-
                    PatchId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", PatchOperation::Checkout))
+
                    .with_id(PatchId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('d'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", PatchOperation::Delete)),
-
                    PatchId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", PatchOperation::Delete))
+
                    .with_id(PatchId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('e'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", PatchOperation::Edit)),
-
                    PatchId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", PatchOperation::Edit))
+
                    .with_id(PatchId::from(id));
                Message::Quit(Some(exit))
            }),
            Event::Keyboard(KeyEvent {
                code: Key::Char('m'),
                ..
            }) => submit().map(|id| {
-
                let exit = SelectionExit::new(
-
                    Some(format!("{}", PatchOperation::Comment)),
-
                    PatchId::from(id),
-
                );
+
                let exit = SelectionExit::default()
+
                    .with_operation(format!("{}", PatchOperation::Comment))
+
                    .with_id(PatchId::from(id));
                Message::Quit(Some(exit))
            }),
            _ => None,
modified src/lib.rs
@@ -50,20 +50,27 @@ pub struct Exit<T> {
}

/// The output that is returned by all selection interfaces.
-
#[derive(Clone, Debug, Eq, PartialEq)]
+
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct SelectionExit {
    operation: Option<String>,
-
    id: ObjectId,
+
    ids: Vec<ObjectId>,
    args: Vec<String>,
}

impl SelectionExit {
-
    pub fn new(operation: Option<String>, id: ObjectId) -> Self {
-
        Self {
-
            operation,
-
            id,
-
            args: vec![],
-
        }
+
    pub fn with_operation(mut self, operation: String) -> Self {
+
        self.operation = Some(operation);
+
        self
+
    }
+

+
    pub fn with_id(mut self, id: ObjectId) -> Self {
+
        self.ids.push(id);
+
        self
+
    }
+

+
    pub fn with_args(mut self, arg: String) -> Self {
+
        self.args.push(arg);
+
        self
    }
}

@@ -74,7 +81,14 @@ impl Serialize for SelectionExit {
    {
        let mut state = serializer.serialize_struct("", 3)?;
        state.serialize_field("operation", &self.operation)?;
-
        state.serialize_field("id", &format!("{}", &self.id))?;
+
        state.serialize_field(
+
            "ids",
+
            &self
+
                .ids
+
                .iter()
+
                .map(|id| format!("{}", id))
+
                .collect::<Vec<_>>(),
+
        )?;
        state.serialize_field("args", &self.args)?;
        state.end()
    }