git clone https://garage44.eu/jeroen/pinnacle.git.. /programs/src/bin/ask.rs
//! The command `ask`: asks whoever is at the terminal three things, a line
//! of text, a choice and a yes or no, and says what it heard. What a
//! command that needs an answer does: an `Ask` record, not raw mode.
#![no_std]
#![no_main]
extern crate alloc;
use pinnacle_rt::output::{AskKind, Output};
#[unsafe(no_mangle)]
fn main(argument: u64) -> u64 {
let out = Output::start(argument);
let Some(name) = out.ask(AskKind::Text, "What is your name?", &[]) else {
return out.status(1, "No one to ask");
};
let Some(fruit) = out.ask(AskKind::Choice, "Which fruit?", &["Apple", "Pear", "Cherry"]) else {
return out.status(1, "No answer");
};
let Some(sure) = out.ask(AskKind::YesNo, "Is that your final answer?", &[]) else {
return out.status(1, "No answer");
};
let sure = if sure == "Yes" {
"and you are sure"
} else {
"but you are not sure"
};
out.text(&alloc::format!("Hello {name}: you chose {fruit}, {sure}."));
out.status(0, "")
}