1use std::io::Write;
2
3use libcros::{
4 LOG,
5 ui::{header::ui_header, menu::selection_menu, *},
6};
7
8const SPLASH: &str = concat!(
9 r#"example splash here
10(can be multi-line)"#
11);
12
13fn menu_handler(option: MenuOption) {
14 if !option.enabled {
15 return;
16 }
17
18 match option.text.as_str() {
19 "Foobar" => {
20 LOG!("selected foobar");
21 }
22
23 "Example" => {
24 LOG!("selected example");
25 }
26
27 "Exit" => {
28 std::process::exit(0);
29 }
30
31 _ => {
32 LOG!("invalid option");
33 }
34 }
35
36 utils::enter_to_continue();
37}
38
39fn main() {
40 let mut text = String::new();
41 text.push_str("Example additional text line 1\n");
42 text.push_str("Example additional text line 2\n");
43
44 loop {
45 print!("\x1b[H\x1b[2J");
46 std::io::stdout().flush().unwrap();
47
48 ui_header(&SPLASH, &text);
49
50 let options = vec![
51 MenuOption::new("Foobar", true, constants::COLOR_RESET),
52 MenuOption::new("Example", true, constants::COLOR_GREEN_B),
53 MenuOption::new("Disabled", false, constants::COLOR_RESET),
54 MenuOption::new("Exit", true, constants::COLOR_RESET),
55 ];
56
57 if let Some(choice) = selection_menu(&options) {
58 menu_handler(options[choice].clone());
59 }
60 }
61}