1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use web_sys::Element;
pub enum TargetElement {
Body,
Element(Element),
TagName(String),
Id(String),
}
pub struct Options {
pub prompt: Option<String>,
pub element: TargetElement,
}
impl Default for Options {
fn default() -> Self {
Options {
prompt: None,
element: TargetElement::Body,
}
}
}
impl Options {
pub fn new() -> Options {
Options::default()
}
pub fn with_prompt(mut self, prompt: &str) -> Self {
self.prompt = Some(prompt.into());
self
}
pub fn with_element(mut self, element: TargetElement) -> Self {
self.element = element;
self
}
pub fn prompt(&self) -> String {
self.prompt.as_ref().unwrap_or(&"$ ".to_string()).clone()
}
}