mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
InputType prop
This commit is contained in:
@@ -41,6 +41,7 @@ pub struct Props {
|
|||||||
pub bold: bool, // Text bold
|
pub bold: bool, // Text bold
|
||||||
pub italic: bool, // Italic
|
pub italic: bool, // Italic
|
||||||
pub underlined: bool, // Underlined
|
pub underlined: bool, // Underlined
|
||||||
|
pub input_type: InputType, // Input type
|
||||||
pub texts: TextParts, // text parts
|
pub texts: TextParts, // text parts
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ impl Default for Props {
|
|||||||
bold: false,
|
bold: false,
|
||||||
italic: false,
|
italic: false,
|
||||||
underlined: false,
|
underlined: false,
|
||||||
|
input_type: InputType::Text,
|
||||||
texts: TextParts::default(),
|
texts: TextParts::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,6 +208,16 @@ impl PropsBuilder {
|
|||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### with_input
|
||||||
|
///
|
||||||
|
/// Set input type for component
|
||||||
|
pub fn with_input(&mut self, input_type: InputType) -> &mut Self {
|
||||||
|
if let Some(props) = self.props.as_mut() {
|
||||||
|
props.input_type = input_type;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PropsBuilder {
|
impl Default for PropsBuilder {
|
||||||
@@ -245,6 +257,18 @@ impl Default for TextParts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Input Type
|
||||||
|
|
||||||
|
/// ## InputType
|
||||||
|
///
|
||||||
|
/// Input type for text inputs
|
||||||
|
#[derive(Clone, PartialEq, std::fmt::Debug)]
|
||||||
|
pub enum InputType {
|
||||||
|
Text,
|
||||||
|
Number,
|
||||||
|
Password,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@@ -261,6 +285,7 @@ mod tests {
|
|||||||
assert_eq!(props.italic, false);
|
assert_eq!(props.italic, false);
|
||||||
assert_eq!(props.underlined, false);
|
assert_eq!(props.underlined, false);
|
||||||
assert!(props.texts.title.is_none());
|
assert!(props.texts.title.is_none());
|
||||||
|
assert_eq!(props.input_type, InputType::Text);
|
||||||
assert!(props.texts.body.is_none());
|
assert!(props.texts.body.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +314,7 @@ mod tests {
|
|||||||
Some(String::from("hello")),
|
Some(String::from("hello")),
|
||||||
Some(vec![String::from("hey")]),
|
Some(vec![String::from("hey")]),
|
||||||
))
|
))
|
||||||
|
.with_input(InputType::Password)
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(props.background, Color::Blue);
|
assert_eq!(props.background, Color::Blue);
|
||||||
assert_eq!(props.bold, true);
|
assert_eq!(props.bold, true);
|
||||||
@@ -296,6 +322,7 @@ mod tests {
|
|||||||
assert_eq!(props.foreground, Color::Green);
|
assert_eq!(props.foreground, Color::Green);
|
||||||
assert_eq!(props.italic, true);
|
assert_eq!(props.italic, true);
|
||||||
assert_eq!(props.texts.title.as_ref().unwrap().as_str(), "hello");
|
assert_eq!(props.texts.title.as_ref().unwrap().as_str(), "hello");
|
||||||
|
assert_eq!(props.input_type, InputType::Password);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
props.texts.body.as_ref().unwrap().get(0).unwrap().as_str(),
|
props.texts.body.as_ref().unwrap().get(0).unwrap().as_str(),
|
||||||
"hey"
|
"hey"
|
||||||
|
|||||||
Reference in New Issue
Block a user