pub fn ask<M>(
view: impl Into<View<M>>,
options: AskOptions,
) -> Result<Answer, Error>Expand description
Asks one question: shows view (a form) and returns its submission.
The form is a flow surface that stays in the scrollback. The answer is
the first action whose act is the submit action, or
Answer::Cancelled on Escape, Ctrl+C or Ctrl+D. Without TSP it is
Answer::Unsupported.
§Errors
When I/O fails or two siblings share an id.
§Example
use tern_sdk::{
Answer, AskOptions,
ui::{Actions, View, html},
};
let view: View = View::new().main([html::form()
.child(
html::label()
.child(html::checkbox("notify", "on"))
.child(html::span("Notify me")),
)
.child(html::button("OK").actions(Actions::new().click("submit")))]);
match tern_sdk::ask(view, AskOptions::new())? {
Answer::Submitted(s) => println!("{:?}", s.values),
Answer::Cancelled => println!("cancelled"),
Answer::Unsupported => println!("no TSP"),
}Examples found in repository?
examples/ask.rs (line 74)
73fn main() -> Result<(), tern_sdk::Error> {
74 let answer = tern_sdk::ask(view(), AskOptions::new().css(CSS))?;
75 match answer {
76 Answer::Submitted(submission) => {
77 let size = submission.values.get("size").and_then(|v| v.as_str());
78 match size {
79 Some(v) => println!("Size: {} ({v})", label(v)),
80 None => println!("No size picked."),
81 }
82 },
83 Answer::Cancelled => println!("Cancelled."),
84 Answer::Unsupported => ask_plainly()?,
85 }
86 Ok(())
87}