Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Introduce exit type for selection interfaces
Erik Kundt committed 2 years ago
commit cd59f13733af37dd8102df0cbc0ff9b0f246ad82
parent 653b1c57f7610e0985f4990488e89cbb705f5a9f
1 file changed +34 -0
modified src/lib.rs
@@ -2,6 +2,9 @@ use std::hash::Hash;
use std::time::Duration;

use anyhow::Result;
+
use serde::ser::{Serialize, SerializeStruct, Serializer};
+

+
use radicle::cob::ObjectId;

use tuirealm::terminal::TerminalBridge;
use tuirealm::tui::layout::Rect;
@@ -46,6 +49,37 @@ pub struct Exit<T> {
    pub value: Option<T>,
}

+
/// The output that is returned by all selection interfaces.
+
#[derive(Clone, Debug, Eq, PartialEq)]
+
pub struct SelectionExit {
+
    operation: Option<String>,
+
    id: ObjectId,
+
    args: Vec<String>,
+
}
+

+
impl SelectionExit {
+
    pub fn new(operation: Option<String>, id: ObjectId) -> Self {
+
        Self {
+
            operation,
+
            id,
+
            args: vec![],
+
        }
+
    }
+
}
+

+
impl Serialize for SelectionExit {
+
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+
    where
+
        S: Serializer,
+
    {
+
        let mut state = serializer.serialize_struct("", 3)?;
+
        state.serialize_field("operation", &self.operation)?;
+
        state.serialize_field("id", &format!("{}", &self.id))?;
+
        state.serialize_field("args", &self.args)?;
+
        state.end()
+
    }
+
}
+

/// A tui-window using the cross-platform Terminal helper provided
/// by tui-realm.
pub struct Window {