Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
patch-select: Use new exit type
Erik Kundt committed 2 years ago
commit 36e13b76e0998beda4df65b8d398a0c0fe49c848
parent cd59f13733af37dd8102df0cbc0ff9b0f246ad82
2 files changed +58 -68
modified 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);
-

-
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))
-
    }
-
}
+
// #[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
/// 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<PatchOperation>,
-
    id: PatchId,
-
}
-

-
impl Output {
-
    pub fn new(operation: Option<PatchOperation>, 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<Output>),
+
    Quit(Option<SelectionExit>),
    Batch(Vec<Message>),
}

@@ -154,7 +127,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
@@ -216,7 +189,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())?;

@@ -255,7 +228,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(),
modified 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<Message, NoUserEvent> for Widget<IdSelect> {
            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<Message, NoUserEvent> for Widget<OperationSelect> {
            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,
        }