|
| 1 | +//! Configuration related commands for Neotron OS |
| 2 | +
|
| 3 | +use crate::{config, println, Ctx}; |
| 4 | + |
| 5 | +/// Called when the "config" command is executed. |
| 6 | +pub fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &mut Ctx) { |
| 7 | + let command = args.get(0).cloned().unwrap_or("print"); |
| 8 | + match command { |
| 9 | + "reset" => match config::Config::load() { |
| 10 | + Ok(new_config) => { |
| 11 | + ctx.config = new_config; |
| 12 | + println!("Loaded OK."); |
| 13 | + } |
| 14 | + Err(e) => { |
| 15 | + println!("Error loading; {}", e); |
| 16 | + } |
| 17 | + }, |
| 18 | + "save" => match ctx.config.save() { |
| 19 | + Ok(_) => { |
| 20 | + println!("Saved OK."); |
| 21 | + } |
| 22 | + Err(e) => { |
| 23 | + println!("Error saving: {}", e); |
| 24 | + } |
| 25 | + }, |
| 26 | + "vga" => match args.get(1).cloned() { |
| 27 | + Some("on") => { |
| 28 | + ctx.config.set_vga_console(true); |
| 29 | + println!("VGA now on"); |
| 30 | + } |
| 31 | + Some("off") => { |
| 32 | + ctx.config.set_vga_console(false); |
| 33 | + println!("VGA now off"); |
| 34 | + } |
| 35 | + _ => { |
| 36 | + println!("Give on or off as argument"); |
| 37 | + } |
| 38 | + }, |
| 39 | + "serial" => match (args.get(1).cloned(), args.get(1).map(|s| s.parse::<u32>())) { |
| 40 | + (_, Some(Ok(baud))) => { |
| 41 | + println!("Turning serial console on at {} bps", baud); |
| 42 | + ctx.config.set_serial_console_on(baud); |
| 43 | + } |
| 44 | + (Some("off"), _) => { |
| 45 | + println!("Turning serial console off"); |
| 46 | + ctx.config.set_serial_console_off(); |
| 47 | + } |
| 48 | + _ => { |
| 49 | + println!("Give off or an integer as argument"); |
| 50 | + } |
| 51 | + }, |
| 52 | + "print" => { |
| 53 | + println!("VGA : {}", ctx.config.get_vga_console()); |
| 54 | + match ctx.config.get_serial_console() { |
| 55 | + None => { |
| 56 | + println!("Serial: off"); |
| 57 | + } |
| 58 | + Some((_port, config)) => { |
| 59 | + println!("Serial: {} bps", config.data_rate_bps); |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + _ => { |
| 64 | + println!("config print - print the config"); |
| 65 | + println!("config help - print this help text"); |
| 66 | + println!("config reset - load config from BIOS store"); |
| 67 | + println!("config save - save config to BIOS store"); |
| 68 | + println!("config vga on - turn VGA on"); |
| 69 | + println!("config vga off - turn VGA off"); |
| 70 | + println!("config serial off - turn serial console off"); |
| 71 | + println!("config serial <baud> - turn serial console on with given baud rate"); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments