use rustofi::components::ActionList;
use rustofi::RustofiResult;
#[derive(Clone)]
pub struct Person {
pub age: i32,
pub name: String
}
impl std::fmt::Display for Person {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.name) }
}
fn simple_app(person: Person) -> RustofiResult {
let rustofi_entries = vec!["Age Up".to_string(), "Age Down".to_string()];
ActionList::new(person.clone(), rustofi_entries, Box::new(simple_callback))
.display(format!("looking at {}, age {}", person.name, person.age))
}
pub fn simple_callback(person: &Person, action: &String) -> RustofiResult {
println!("selected action: {}", action);
if action == "Age Up" {
println!("{} age + 5 is: {} ", person.name, person.age);
} else if action == "Age Down" {
println!("{} age - 5 is: {}", person.name, person.age);
} else {
println!("invalid action!");
return RustofiResult::Error;
}
RustofiResult::Success
}
fn main() {
let mut p = Person {
age: 15,
name: "joe".to_string()
};
loop {
match simple_app(p.clone()) {
RustofiResult::Error => break,
RustofiResult::Exit => break,
RustofiResult::Cancel => break,
RustofiResult::Blank => break, _ => {}
}
}
}