pub struct Textarea { /* private fields */ }Expand description
A multi-line text input prompt.
Implementations§
Source§impl Textarea
impl Textarea
Sourcepub fn new(prompt: impl Into<String>) -> Self
pub fn new(prompt: impl Into<String>) -> Self
Creates a multi-line prompt with the given label.
Examples found in repository?
examples/prompt-readme.rs (line 84)
65fn left_column() -> Rendered {
66 vstack(
67 &[
68 Confirm::new("Deploy to production?").default_yes().frame(),
69 blank(),
70 TextInput::new("Service").initial("api-gateway").frame(),
71 PasswordInput::new("Password").initial("hunter2").frame(),
72 NumberInput::new("Replicas")
73 .initial(3.0)
74 .range(1.0, 10.0)
75 .frame(),
76 TextInput::new("Email")
77 .placeholder("you@example.com")
78 .frame(),
79 TextInput::new("Region")
80 .initial("eu-")
81 .suggestions(["eu-central-1"])
82 .frame(),
83 blank(),
84 Textarea::new("Notes")
85 .initial("first line\nsecond line\nthird line")
86 .frame(),
87 ],
88 0,
89 )
90}More examples
examples/prompts.rs (line 56)
28fn main() -> sparcli::Result<()> {
29 footer_hint()?;
30
31 let name = get!(
32 TextInput::new("Your name?")
33 .placeholder("e.g. Alice")
34 .validate(non_empty())
35 .run()?
36 );
37
38 let _username = get!(
39 TextInput::new("Username?")
40 .char_filter(alnum())
41 .max_chars(16)
42 .suggestions(["alice", "albert", "bob", "carol"])
43 .history(["alice", "bob"])
44 .run()?
45 );
46
47 let _password = get!(PasswordInput::new("Password?").mask("•").run()?);
48
49 let age = get!(
50 NumberInput::new("Age? (try `= 20 + 2`)")
51 .range(0.0, 130.0)
52 .calculator()
53 .run()?
54 );
55
56 let _bio = get!(Textarea::new("Short bio (Ctrl-D to submit):").run()?);
57
58 let color = get!(
59 Select::new("Favorite color?")
60 .options(["red", "green", "blue"])
61 .run()?
62 );
63
64 let toppings = get!(
65 Select::new("Pick toppings (Space to toggle):")
66 .options(["cheese", "mushroom", "olive", "onion"])
67 .multi()
68 .run_multi()?
69 );
70
71 let _fruit = get!(pick_fruit()?);
72
73 let date = get!(DatePicker::new("Pick a date:").run()?);
74
75 let confirmed = matches!(
76 Confirm::new("Save everything?")
77 .default_yes()
78 .labels("Save", "Discard")
79 .run()?,
80 Outcome::Submitted(true)
81 );
82
83 if confirmed {
84 Alert::success(format!(
85 "Saved {name}, age {age:.0}, color #{color}, {} toppings, \
86 date {}-{:02}-{:02}.",
87 toppings.len(),
88 date.year,
89 date.month,
90 date.day,
91 ))
92 .print()?;
93 } else {
94 cancelled()?;
95 }
96 Ok(())
97}Sourcepub fn initial(self, value: impl Into<String>) -> Self
pub fn initial(self, value: impl Into<String>) -> Self
Sets the initial multi-line value.
Examples found in repository?
examples/prompt-readme.rs (line 85)
65fn left_column() -> Rendered {
66 vstack(
67 &[
68 Confirm::new("Deploy to production?").default_yes().frame(),
69 blank(),
70 TextInput::new("Service").initial("api-gateway").frame(),
71 PasswordInput::new("Password").initial("hunter2").frame(),
72 NumberInput::new("Replicas")
73 .initial(3.0)
74 .range(1.0, 10.0)
75 .frame(),
76 TextInput::new("Email")
77 .placeholder("you@example.com")
78 .frame(),
79 TextInput::new("Region")
80 .initial("eu-")
81 .suggestions(["eu-central-1"])
82 .frame(),
83 blank(),
84 Textarea::new("Notes")
85 .initial("first line\nsecond line\nthird line")
86 .frame(),
87 ],
88 0,
89 )
90}Sourcepub fn editor_command(self, command: impl Into<String>) -> Self
pub fn editor_command(self, command: impl Into<String>) -> Self
Sets the editor command (implies editor).
Sourcepub fn run(self) -> Result<Outcome<String>>
pub fn run(self) -> Result<Outcome<String>>
Runs the prompt on the real terminal.
§Errors
Returns SparcliError::NoTerminal without an interactive terminal,
or SparcliError::Io on a terminal failure.
Examples found in repository?
examples/prompts.rs (line 56)
28fn main() -> sparcli::Result<()> {
29 footer_hint()?;
30
31 let name = get!(
32 TextInput::new("Your name?")
33 .placeholder("e.g. Alice")
34 .validate(non_empty())
35 .run()?
36 );
37
38 let _username = get!(
39 TextInput::new("Username?")
40 .char_filter(alnum())
41 .max_chars(16)
42 .suggestions(["alice", "albert", "bob", "carol"])
43 .history(["alice", "bob"])
44 .run()?
45 );
46
47 let _password = get!(PasswordInput::new("Password?").mask("•").run()?);
48
49 let age = get!(
50 NumberInput::new("Age? (try `= 20 + 2`)")
51 .range(0.0, 130.0)
52 .calculator()
53 .run()?
54 );
55
56 let _bio = get!(Textarea::new("Short bio (Ctrl-D to submit):").run()?);
57
58 let color = get!(
59 Select::new("Favorite color?")
60 .options(["red", "green", "blue"])
61 .run()?
62 );
63
64 let toppings = get!(
65 Select::new("Pick toppings (Space to toggle):")
66 .options(["cheese", "mushroom", "olive", "onion"])
67 .multi()
68 .run_multi()?
69 );
70
71 let _fruit = get!(pick_fruit()?);
72
73 let date = get!(DatePicker::new("Pick a date:").run()?);
74
75 let confirmed = matches!(
76 Confirm::new("Save everything?")
77 .default_yes()
78 .labels("Save", "Discard")
79 .run()?,
80 Outcome::Submitted(true)
81 );
82
83 if confirmed {
84 Alert::success(format!(
85 "Saved {name}, age {age:.0}, color #{color}, {} toppings, \
86 date {}-{:02}-{:02}.",
87 toppings.len(),
88 date.year,
89 date.month,
90 date.day,
91 ))
92 .print()?;
93 } else {
94 cancelled()?;
95 }
96 Ok(())
97}Sourcepub fn frame(&self) -> Rendered
pub fn frame(&self) -> Rendered
Renders the prompt’s static frame without running it (for previews and README screenshots).
Examples found in repository?
examples/prompt-readme.rs (line 86)
65fn left_column() -> Rendered {
66 vstack(
67 &[
68 Confirm::new("Deploy to production?").default_yes().frame(),
69 blank(),
70 TextInput::new("Service").initial("api-gateway").frame(),
71 PasswordInput::new("Password").initial("hunter2").frame(),
72 NumberInput::new("Replicas")
73 .initial(3.0)
74 .range(1.0, 10.0)
75 .frame(),
76 TextInput::new("Email")
77 .placeholder("you@example.com")
78 .frame(),
79 TextInput::new("Region")
80 .initial("eu-")
81 .suggestions(["eu-central-1"])
82 .frame(),
83 blank(),
84 Textarea::new("Notes")
85 .initial("first line\nsecond line\nthird line")
86 .frame(),
87 ],
88 0,
89 )
90}Auto Trait Implementations§
impl Freeze for Textarea
impl RefUnwindSafe for Textarea
impl Send for Textarea
impl Sync for Textarea
impl Unpin for Textarea
impl UnsafeUnpin for Textarea
impl UnwindSafe for Textarea
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more