issue-select: Use new exit type

This commit is contained in:
Erik Kundt
2024-01-30 16:34:44 +01:00
parent 36e13b76e0
commit db1ec6e488
3 changed files with 29 additions and 40 deletions
+1 -1
View File
@@ -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}");
+5 -29
View File
@@ -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<IssueOperation>,
id: IssueId,
}
impl Output {
pub fn new(operation: Option<IssueOperation>, 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<Output>),
Quit(Option<SelectionExit>),
Batch(Vec<Message>),
}
@@ -147,7 +123,7 @@ pub struct App {
quit: bool,
mode: Mode,
filter: Filter,
output: Option<Output>,
output: Option<SelectionExit>,
}
/// Creates a new application using a tui-realm-application, mounts all
@@ -209,7 +185,7 @@ impl App {
}
}
impl Tui<Cid, Message, Output> for App {
impl Tui<Cid, Message, SelectionExit> for App {
fn init(&mut self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
self.view_list(app, &self.theme.clone())?;
@@ -248,7 +224,7 @@ impl Tui<Cid, Message, Output> for App {
}
}
fn exit(&self) -> Option<Exit<Output>> {
fn exit(&self) -> Option<Exit<SelectionExit>> {
if self.quit {
return Some(Exit {
value: self.output.clone(),
+23 -10
View File
@@ -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<Message, NoUserEvent> for Widget<IdSelect> {
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<Message, NoUserEvent> for Widget<OperationSelect> {
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,
}