diff --git a/bin/commands/issue.rs b/bin/commands/issue.rs index a8f882f4..09b7a2fe 100644 --- a/bin/commands/issue.rs +++ b/bin/commands/issue.rs @@ -135,7 +135,7 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()> let output = Window::default().run(&mut app, 1000 / FPS)?; let output = output - .map(|o| serde_json::to_string(&o).unwrap_or_default()) + .map(|o| serde_json::to_string(&o).unwrap_or_default()) .unwrap_or_default(); eprint!("{output}"); diff --git a/bin/commands/issue/select.rs b/bin/commands/issue/select.rs index ecc49b3a..6ee77fa8 100644 --- a/bin/commands/issue/select.rs +++ b/bin/commands/issue/select.rs @@ -9,7 +9,6 @@ use std::fmt::Display; use std::hash::Hash; use anyhow::Result; -use radicle::issue::IssueId; use serde::{Serialize, Serializer}; use tuirealm::application::PollStrategy; @@ -23,7 +22,7 @@ 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; @@ -93,29 +92,6 @@ impl Display for IssueOperation { } } -/// The application's output that depends on the application's -/// subject. -#[derive(Clone, Debug, Eq, PartialEq, Serialize)] -pub struct Output { - operation: Option, - id: IssueId, -} - -impl Output { - pub fn new(operation: Option, id: IssueId) -> 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, @@ -136,7 +112,7 @@ pub enum Cid { pub enum Message { #[default] Tick, - Quit(Option), + Quit(Option), Batch(Vec), } @@ -147,7 +123,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 @@ -209,7 +185,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())?; @@ -248,7 +224,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/issue/select/event.rs b/bin/commands/issue/select/event.rs index 22f6608d..bc064b27 100644 --- a/bin/commands/issue/select/event.rs +++ b/bin/commands/issue/select/event.rs @@ -1,4 +1,5 @@ use radicle::issue::IssueId; +use tui::SelectionExit; use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection}; use tuirealm::event::{Event, Key, KeyEvent}; use tuirealm::{MockComponent, NoUserEvent, State, StateValue}; @@ -12,7 +13,7 @@ use tui::ui::widget::list::PropertyList; use tui::ui::widget::Widget; use super::ui::{IdSelect, OperationSelect}; -use super::{IssueOperation, Message, Output}; +use super::{IssueOperation, Message}; /// 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 @@ -66,7 +67,7 @@ impl tuirealm::Component for Widget { Event::Keyboard(KeyEvent { code: Key::Enter, .. }) => submit().map(|id| { - let output = Output::new(None, IssueId::from(id)); + let output = SelectionExit::new(None, IssueId::from(id)); Message::Quit(Some(output)) }), _ => None, @@ -109,29 +110,41 @@ impl tuirealm::Component for Widget { Event::Keyboard(KeyEvent { code: Key::Enter, .. }) => submit().map(|id| { - let output = Output::new(Some(IssueOperation::Show), IssueId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", IssueOperation::Show)), + IssueId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('d'), .. }) => submit().map(|id| { - let output = Output::new(Some(IssueOperation::Delete), IssueId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", IssueOperation::Delete)), + IssueId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('e'), .. }) => submit().map(|id| { - let output = Output::new(Some(IssueOperation::Edit), IssueId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", IssueOperation::Edit)), + IssueId::from(id), + ); + Message::Quit(Some(exit)) }), Event::Keyboard(KeyEvent { code: Key::Char('m'), .. }) => submit().map(|id| { - let output = Output::new(Some(IssueOperation::Comment), IssueId::from(id)); - Message::Quit(Some(output)) + let exit = SelectionExit::new( + Some(format!("{}", IssueOperation::Comment)), + IssueId::from(id), + ); + Message::Quit(Some(exit)) }), _ => None, }