use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Confirm {
title: String,
message: String,
#[serde(skip_serializing_if = "Option::is_none")]
confirm_label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
cancel_label: Option<String>,
#[serde(skip_serializing_if = "std::ops::Not::not")]
destructive: bool,
}
impl Confirm {
#[must_use]
pub fn new(title: impl Into<String>, message: impl Into<String>) -> Self {
Self { title: title.into(), message: message.into(), confirm_label: None, cancel_label: None, destructive: false }
}
#[must_use]
pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
self.confirm_label = Some(label.into());
self
}
#[must_use]
pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
self.cancel_label = Some(label.into());
self
}
#[must_use]
pub fn destructive(mut self) -> Self {
self.destructive = true;
self
}
pub(crate) fn to_input(&self) -> String {
serde_json::to_string(self).expect("serialize confirm")
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct Picker {
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
confirm_label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
cancel_label: Option<String>,
}
impl Picker {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
#[must_use]
pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
self.confirm_label = Some(label.into());
self
}
#[must_use]
pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
self.cancel_label = Some(label.into());
self
}
pub(crate) fn to_input(&self) -> String {
serde_json::to_string(self).expect("serialize picker")
}
}