diff --git a/bin/commands/patch/select.rs b/bin/commands/patch/select.rs index b4eda44e..a0cd27e0 100644 --- a/bin/commands/patch/select.rs +++ b/bin/commands/patch/select.rs @@ -9,7 +9,7 @@ use std::fmt::Display; use std::hash::Hash; use anyhow::Result; -use serde::{Serialize, Serializer}; +use serde::Serialize; use tuirealm::application::PollStrategy; use tuirealm::event::Key; @@ -22,35 +22,35 @@ use tui::context::Context; use tui::ui::subscription; use tui::ui::theme::Theme; -use tui::{Exit, PageStack, Tui}; +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); +// #[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 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 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)) - } -} +// 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 /// which widgets to render and which output to produce. @@ -69,7 +69,6 @@ pub enum Mode { pub enum PatchOperation { Show, Checkout, - Review, Delete, Edit, Comment, @@ -84,9 +83,6 @@ impl Display for PatchOperation { PatchOperation::Checkout => { write!(f, "checkout") } - PatchOperation::Review => { - write!(f, "review") - } PatchOperation::Delete => { write!(f, "delete") } @@ -100,29 +96,6 @@ impl Display for PatchOperation { } } -/// The application's output that depends on the application's -/// subject. -#[derive(Clone, Debug, Eq, PartialEq, Serialize)] -pub struct Output { - operation: Option, - id: PatchId, -} - -impl Output { - pub fn new(operation: Option, id: PatchId) -> Self { - Self { operation, id } - } -} - -impl Display for Output { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.operation { - Some(op) => write!(f, "{} {}", op, self.id), - None => write!(f, "{}", self.id), - } - } -} - #[derive(Debug, Eq, PartialEq, Clone, Hash)] pub enum ListCid { Header, @@ -143,7 +116,7 @@ pub enum Cid { pub enum Message { #[default] Tick, - Quit(Option), + Quit(Option), Batch(Vec), } @@ -154,7 +127,7 @@ pub struct App { quit: bool, mode: Mode, filter: Filter, - output: Option, + output: Option, } /// Creates a new application using a tui-realm-application, mounts all @@ -216,7 +189,7 @@ impl App { } } -impl Tui for App { +impl Tui for App { fn init(&mut self, app: &mut Application) -> Result<()> { self.view_list(app, &self.theme.clone())?; @@ -255,7 +228,7 @@ impl Tui for App { } } - fn exit(&self) -> Option> { + fn exit(&self) -> Option> { if self.quit { return Some(Exit { value: self.output.clone(), diff --git a/bin/commands/patch/select/event.rs b/bin/commands/patch/select/event.rs index 3b80edf6..fa0b8f2b 100644 --- a/bin/commands/patch/select/event.rs +++ b/bin/commands/patch/select/event.rs @@ -1,3 +1,5 @@ +use radicle::patch::PatchId; +use tui::SelectionExit; use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection}; use tuirealm::event::{Event, Key, KeyEvent}; use tuirealm::{MockComponent, NoUserEvent, State, StateValue}; @@ -11,7 +13,7 @@ use tui::ui::widget::list::PropertyList; use tui::ui::widget::Widget; use super::ui::{IdSelect, OperationSelect}; -use super::{Message, Output, PatchId, PatchOperation}; +use super::{Message, PatchOperation}; /// Since the framework does not know the type of messages that are being /// passed around in the app, the following handlers need to be implemented for @@ -65,7 +67,7 @@ impl tuirealm::Component for Widget { Event::Keyboard(KeyEvent { code: Key::Enter, .. }) => submit().map(|id| { - let output = Output::new(None, PatchId::from(id)); + let output = SelectionExit::new(None, PatchId::from(id)); Message::Quit(Some(output)) }), _ => None, @@ -108,36 +110,51 @@ impl tuirealm::Component for Widget { Event::Keyboard(KeyEvent { code: Key::Enter, .. }) => submit().map(|id| { - let output = Output::new(Some(PatchOperation::Show), PatchId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", PatchOperation::Show)), + PatchId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('c'), .. }) => submit().map(|id| { - let output = Output::new(Some(PatchOperation::Checkout), PatchId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", PatchOperation::Checkout)), + PatchId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('d'), .. }) => submit().map(|id| { - let output = Output::new(Some(PatchOperation::Delete), PatchId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", PatchOperation::Delete)), + PatchId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('e'), .. }) => submit().map(|id| { - let output = Output::new(Some(PatchOperation::Edit), PatchId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", PatchOperation::Edit)), + PatchId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('m'), .. }) => submit().map(|id| { - let output = Output::new(Some(PatchOperation::Comment), PatchId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", PatchOperation::Comment)), + PatchId::from(id), + ); + Message::Quit(Some(exit)) }), _ => None, }