diff --git a/bin/commands/issue/select/event.rs b/bin/commands/issue/select/event.rs index bc064b27..4ea5b124 100644 --- a/bin/commands/issue/select/event.rs +++ b/bin/commands/issue/select/event.rs @@ -67,7 +67,7 @@ impl tuirealm::Component for Widget { 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 for Widget { 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, diff --git a/bin/commands/patch/select.rs b/bin/commands/patch/select.rs index a0cd27e0..2400cd3b 100644 --- a/bin/commands/patch/select.rs +++ b/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 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(&self, serializer: S) -> Result -// 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 { diff --git a/bin/commands/patch/select/event.rs b/bin/commands/patch/select/event.rs index fa0b8f2b..facc8c33 100644 --- a/bin/commands/patch/select/event.rs +++ b/bin/commands/patch/select/event.rs @@ -67,7 +67,7 @@ impl tuirealm::Component for Widget { 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 for Widget { 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, diff --git a/src/lib.rs b/src/lib.rs index da0ac79e..0440fe2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,20 +50,27 @@ pub struct Exit { } /// 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, - id: ObjectId, + ids: Vec, args: Vec, } impl SelectionExit { - pub fn new(operation: Option, 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::>(), + )?; state.serialize_field("args", &self.args)?; state.end() }