Skip to content

Commit 76c87dd

Browse files
committed
Add chassis type
1 parent d3db428 commit 76c87dd

File tree

5 files changed

+371
-4
lines changed

5 files changed

+371
-4
lines changed

Cargo.lock

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ anyhow = "1"
1515
clap = { version = "4", features = ["derive", "cargo"] }
1616
libc = "0.2"
1717
uuid = "1"
18+
strum = { version = "0.27", features = ["derive"] }
1819

1920
[profile.release]
2021
lto = "fat"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sudo dmitui
4848
- [x] Firmware (type 0)
4949
- [x] System (type 1)
5050
- [x] Baseboard (type 2)
51+
- [x] Chassis (type 3) (Partially)
5152

5253
## ⚖️ License
5354

src/dmi.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod baseboard;
2+
mod chassis;
23
mod firmware;
34
mod system;
45

@@ -12,6 +13,7 @@ use std::{
1213
use anyhow::{Result, bail};
1314

1415
use crate::dmi::baseboard::Baseboard;
16+
use crate::dmi::chassis::Chassis;
1517
use crate::dmi::firmware::Firmware;
1618
use crate::dmi::system::System;
1719

@@ -29,6 +31,7 @@ pub struct DMI {
2931
firmware: Firmware,
3032
system: System,
3133
baseboard: Baseboard,
34+
chassis: Chassis,
3235
pub focused_section: FocusedSection,
3336
}
3437

@@ -38,6 +41,7 @@ pub enum FocusedSection {
3841
Firmware,
3942
System,
4043
Baseboard,
44+
Chassis,
4145
}
4246

4347
#[derive(Debug)]
@@ -53,6 +57,7 @@ impl From<[u8; 4]> for Header {
5357
0 => StructureType::Firmware,
5458
1 => StructureType::System,
5559
2 => StructureType::Baseboard,
60+
3 => StructureType::Chassis,
5661
127 => StructureType::End,
5762
_ => StructureType::Other,
5863
};
@@ -71,6 +76,7 @@ pub enum StructureType {
7176
Firmware = 0,
7277
System = 1,
7378
Baseboard = 2,
79+
Chassis = 3,
7480
End = 127,
7581
Other = 255,
7682
}
@@ -82,6 +88,7 @@ impl DMI {
8288
let mut firmware: Option<Firmware> = None;
8389
let mut system: Option<System> = None;
8490
let mut baseboard: Option<Baseboard> = None;
91+
let mut chassis: Option<Chassis> = None;
8592

8693
let dmi_file_path = Path::new("/sys/firmware/dmi/tables/DMI");
8794

@@ -149,6 +156,9 @@ impl DMI {
149156
StructureType::Baseboard => {
150157
baseboard = Some(Baseboard::from((data, text)));
151158
}
159+
StructureType::Chassis => {
160+
chassis = Some(Chassis::from((data, text)));
161+
}
152162
_ => {}
153163
}
154164
}
@@ -157,6 +167,7 @@ impl DMI {
157167
firmware: firmware.unwrap(),
158168
system: system.unwrap(),
159169
baseboard: baseboard.unwrap(),
170+
chassis: chassis.unwrap(),
160171
focused_section: FocusedSection::Firmware,
161172
})
162173
}
@@ -168,12 +179,14 @@ impl DMI {
168179
KeyCode::Tab => match self.focused_section {
169180
FocusedSection::Firmware => self.focused_section = FocusedSection::System,
170181
FocusedSection::System => self.focused_section = FocusedSection::Baseboard,
171-
FocusedSection::Baseboard => self.focused_section = FocusedSection::Firmware,
182+
FocusedSection::Baseboard => self.focused_section = FocusedSection::Chassis,
183+
FocusedSection::Chassis => self.focused_section = FocusedSection::Firmware,
172184
},
173185
KeyCode::BackTab => match self.focused_section {
174-
FocusedSection::Firmware => self.focused_section = FocusedSection::Baseboard,
186+
FocusedSection::Firmware => self.focused_section = FocusedSection::Chassis,
175187
FocusedSection::System => self.focused_section = FocusedSection::Firmware,
176188
FocusedSection::Baseboard => self.focused_section = FocusedSection::System,
189+
FocusedSection::Chassis => self.focused_section = FocusedSection::Baseboard,
177190
},
178191
_ => {}
179192
}
@@ -212,6 +225,16 @@ impl DMI {
212225
Span::from(" Baseboard ").fg(Color::DarkGray)
213226
}
214227
}
228+
FocusedSection::Chassis => {
229+
if is_focused {
230+
Span::styled(
231+
" Chassis ",
232+
Style::default().bg(Color::Yellow).fg(Color::White).bold(),
233+
)
234+
} else {
235+
Span::from(" Chassis ").fg(Color::DarkGray)
236+
}
237+
}
215238
}
216239
}
217240

@@ -232,6 +255,7 @@ impl DMI {
232255
self.title_span(FocusedSection::Firmware),
233256
self.title_span(FocusedSection::System),
234257
self.title_span(FocusedSection::Baseboard),
258+
self.title_span(FocusedSection::Chassis),
235259
]))
236260
.title_alignment(Alignment::Left)
237261
.padding(Padding::top(1))
@@ -259,6 +283,9 @@ impl DMI {
259283
FocusedSection::Baseboard => {
260284
self.baseboard.render(frame, section_block);
261285
}
286+
FocusedSection::Chassis => {
287+
self.chassis.render(frame, section_block);
288+
}
262289
}
263290
}
264291
}

0 commit comments

Comments
 (0)