Skip to content

Commit 824e569

Browse files
Move ITEMS into submodules.
1 parent a5028f7 commit 824e569

File tree

5 files changed

+77
-62
lines changed

5 files changed

+77
-62
lines changed

src/commands/config.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,26 @@
22
33
use crate::{config, println, Ctx};
44

5+
pub static COMMAND_ITEM: menu::Item<Ctx> = menu::Item {
6+
item_type: menu::ItemType::Callback {
7+
function: command,
8+
parameters: &[
9+
menu::Parameter::Optional {
10+
parameter_name: "command",
11+
help: Some("Which operation to perform (try help)"),
12+
},
13+
menu::Parameter::Optional {
14+
parameter_name: "value",
15+
help: Some("new value for the setting"),
16+
},
17+
],
18+
},
19+
command: "config",
20+
help: Some("Handle non-volatile OS configuration"),
21+
};
22+
523
/// Called when the "config" command is executed.
6-
pub fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &mut Ctx) {
24+
fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &mut Ctx) {
725
let command = args.get(0).cloned().unwrap_or("print");
826
match command {
927
"reset" => match config::Config::load() {

src/commands/hardware.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
33
use crate::{bios, println, Ctx, API};
44

5-
/// Called when the "lshw" command is executed.
6-
pub fn lshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
5+
pub static LSHW_ITEM: menu::Item<Ctx> = menu::Item {
6+
item_type: menu::ItemType::Callback {
7+
function: bioshw,
8+
parameters: &[],
9+
},
10+
command: "bioshw",
11+
help: Some("List all the BIOS hardware"),
12+
};
13+
14+
/// Called when the "bioshw" command is executed.
15+
fn bioshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
716
let api = API.get();
817
let mut found = false;
918

@@ -18,35 +27,42 @@ pub fn lshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _c
1827
println!(" None");
1928
}
2029

21-
println!();
2230
found = false;
2331

2432
println!("Serial Devices:");
2533
for dev_idx in 0..=255u8 {
2634
if let bios::Option::Some(device_info) = (api.serial_get_info)(dev_idx) {
27-
println!(" {}: {:?}", dev_idx, device_info);
35+
println!(
36+
" {}: {} {:?}",
37+
dev_idx, device_info.name, device_info.device_type
38+
);
2839
found = true;
2940
}
3041
}
3142
if !found {
3243
println!(" None");
3344
}
3445

35-
println!();
3646
found = false;
3747

3848
println!("Block Devices:");
3949
for dev_idx in 0..=255u8 {
4050
if let bios::Option::Some(device_info) = (api.block_dev_get_info)(dev_idx) {
41-
println!(" {}: {:?}", dev_idx, device_info);
51+
println!(
52+
" {}: {} {:?} bs={} size={} MiB",
53+
dev_idx,
54+
device_info.name,
55+
device_info.device_type,
56+
device_info.block_size,
57+
(device_info.num_blocks * u64::from(device_info.block_size)) / (1024 * 1024)
58+
);
4259
found = true;
4360
}
4461
}
4562
if !found {
4663
println!(" None");
4764
}
4865

49-
println!();
5066
found = false;
5167

5268
println!("I2C Buses:");
@@ -60,7 +76,6 @@ pub fn lshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _c
6076
println!(" None");
6177
}
6278

63-
println!();
6479
found = false;
6580

6681
println!("Neotron Bus Devices:");
@@ -74,7 +89,6 @@ pub fn lshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _c
7489
println!(" None");
7590
}
7691

77-
println!();
7892
found = false;
7993

8094
println!("Audio Mixers:");

src/commands/input.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
33
use crate::{bios, println, Ctx, API};
44

5+
pub static KBTEST_ITEM: menu::Item<Ctx> = menu::Item {
6+
item_type: menu::ItemType::Callback {
7+
function: kbtest,
8+
parameters: &[],
9+
},
10+
command: "input_kbtest",
11+
help: Some("Test the keyboard (press ESC to quit)"),
12+
};
13+
514
/// Called when the "kbtest" command is executed.
6-
pub fn kbtest(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], ctx: &mut Ctx) {
15+
fn kbtest(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], ctx: &mut Ctx) {
716
let api = API.get();
817
loop {
918
match (api.hid_get_event)() {

src/commands/mod.rs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,11 @@ mod screen;
1212
pub static OS_MENU: menu::Menu<Ctx> = menu::Menu {
1313
label: "root",
1414
items: &[
15-
&menu::Item {
16-
item_type: menu::ItemType::Callback {
17-
function: hardware::lshw,
18-
parameters: &[],
19-
},
20-
command: "lshw",
21-
help: Some("List all the hardware"),
22-
},
23-
&menu::Item {
24-
item_type: menu::ItemType::Callback {
25-
function: screen::clear,
26-
parameters: &[],
27-
},
28-
command: "clear",
29-
help: Some("Clear the screen"),
30-
},
31-
&menu::Item {
32-
item_type: menu::ItemType::Callback {
33-
function: screen::fill,
34-
parameters: &[],
35-
},
36-
command: "fill",
37-
help: Some("Fill the screen with characters"),
38-
},
39-
&menu::Item {
40-
item_type: menu::ItemType::Callback {
41-
function: config::command,
42-
parameters: &[
43-
menu::Parameter::Optional {
44-
parameter_name: "command",
45-
help: Some("Which operation to perform (try help)"),
46-
},
47-
menu::Parameter::Optional {
48-
parameter_name: "value",
49-
help: Some("new value for the setting"),
50-
},
51-
],
52-
},
53-
command: "config",
54-
help: Some("Handle non-volatile OS configuration"),
55-
},
56-
&menu::Item {
57-
item_type: menu::ItemType::Callback {
58-
function: input::kbtest,
59-
parameters: &[],
60-
},
61-
command: "kbtest",
62-
help: Some("Test the keyboard (press ESC to quit)"),
63-
},
15+
&config::COMMAND_ITEM,
16+
&hardware::LSHW_ITEM,
17+
&screen::CLEAR_ITEM,
18+
&screen::FILL_ITEM,
19+
&input::KBTEST_ITEM,
6420
],
6521
entry: None,
6622
exit: None,

src/commands/screen.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@
22
33
use crate::{print, println, Ctx, API, VGA_CONSOLE};
44

5+
pub static CLEAR_ITEM: menu::Item<Ctx> = menu::Item {
6+
item_type: menu::ItemType::Callback {
7+
function: clear,
8+
parameters: &[],
9+
},
10+
command: "screen_clear",
11+
help: Some("Clear the screen"),
12+
};
13+
14+
pub static FILL_ITEM: menu::Item<Ctx> = menu::Item {
15+
item_type: menu::ItemType::Callback {
16+
function: fill,
17+
parameters: &[],
18+
},
19+
command: "screen_fill",
20+
help: Some("Fill the screen with characters"),
21+
};
22+
523
/// Called when the "clear" command is executed.
6-
pub fn clear(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
24+
fn clear(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
725
if let Some(ref mut console) = unsafe { &mut VGA_CONSOLE } {
826
console.clear();
927
}
1028
}
1129

1230
/// Called when the "fill" command is executed.
13-
pub fn fill(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
31+
fn fill(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
1432
if let Some(ref mut console) = unsafe { &mut VGA_CONSOLE } {
1533
console.clear();
1634
}

0 commit comments

Comments
 (0)