Skip to content

Commit 93658a9

Browse files
committed
v0.1.9-prerelease with key_eventloop and compatible with all resolutions
1 parent bb950b0 commit 93658a9

File tree

8 files changed

+120
-81
lines changed

8 files changed

+120
-81
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Preview
22
![Preview error](https://github.com/yaroslav957/efifetch/blob/master/previews/v0.1.8.1.png)
33

4+
efifetch currently supports only VGA output (some resolution issues with serialport0 on QEMU)
5+
46
# How to use
57

68
## in a VM

src/assets/uefi.logo

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.^!??~
2+
.:~7?7~: .:!~:
3+
^7?7~: :~?5PY7: .
4+
^!JPGJ. ~?YPPJ!: :~?!^
5+
GGGGG5~. ??7^ .:~7J5GGGG
6+
GP?!~!77!~^. .:^7JJ7~^::!PG
7+
P~ !YP5YYY5PGJ^ 7G
8+
J :^ !PGGGGP~ :77.^!?YG
9+
J ~J7. ^PGGP^ YGZJ?!:7G
10+
P: ~GG? 7?5: 7G
11+
GJ 7J!^.. YG7 :5. 7G
12+
GGJ: :7?7??!:JG7 ~Y5 7G
13+
^!YY7: ^!?PG? 5G5 ^^
14+
:~!!^: !GG? YPJ
15+
.:^!?YPGGG? ^:.
16+
^!JPP!

src/logic/draw/cpu_page.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
fn _todo() {
1+
use crate::logic::info::cpu::CpuInfo;
2+
3+
#[allow(unused)]
4+
pub fn draw(info: &CpuInfo) {
25
todo!();
36
}

src/logic/draw/mem_page.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
fn _todo() {
1+
use crate::logic::info::mem::MemInfo;
2+
3+
#[allow(unused)]
4+
pub fn draw(info: &MemInfo) {
25
todo!();
36
}

src/logic/draw/menu_page.rs

Lines changed: 54 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ use alloc::format;
66
use uefi::{
77
boot::ScopedProtocol,
88
print,
9-
proto::{
10-
console::text::{Color, Output},
11-
network::snp::SimpleNetwork,
12-
},
13-
Result, Status,
9+
proto::console::text::{Color, Output},
10+
Result,
1411
};
1512

13+
const LOGO: &'static str = include_str!("../../assets/uefi.logo");
1614
const VERSION: &'static str = " Efifetch 0.1.9";
1715
const COLORS: [Color; 14] = [
1816
Color::LightRed,
@@ -30,108 +28,88 @@ const COLORS: [Color; 14] = [
3028
Color::Magenta,
3129
Color::Black,
3230
];
33-
const LOGO: &'static str = r#"
34-
.^!??~
35-
.:~7?7~: .:!~:
36-
^7?7~: :~?5PY7: .
37-
^!JPGJ. ~?YPPJ!: :~?!^
38-
GGGGG5~. ??7^ .:~7J5GGGG
39-
GP?!~!77!~^. .:^7JJ7~^::!PG
40-
P~ !YP5YYY5PGJ^ 7G
41-
J :^ !PGGGGP~ :77.^!?YG
42-
J ~J7. ^PGGP^ YGPJ?!:7G
43-
P: ~GG? 7?5: 7G
44-
GJ 7J!^.. YG7 :5. 7G
45-
GGJ: :7?7??!:JG7 ~Y5 7G
46-
^!YY7: ^!?PG? 5G5 ^^
47-
:~!!^: !GG? YPJ
48-
.:^!?YPGGG? ^:.
49-
^!JPP!
50-
"#;
5131

52-
pub fn draw(
53-
mut stdout: &mut ScopedProtocol<Output>,
54-
net: &ScopedProtocol<SimpleNetwork>,
55-
date: Date,
56-
) -> Result<Status> {
32+
pub fn draw(mut stdout: &mut ScopedProtocol<Output>, date: Date) -> Result<()> {
5733
stdout.clear()?;
5834

5935
let (rows, columns) = get_resolution(&mut stdout)?;
60-
let mut logo = LOGO.lines().skip(1);
36+
let mut logo = LOGO.lines();
6137

6238
let resolution = format!(" Resolution: {}x{}", columns, rows);
6339
let date = format!(" BIOS Date: {}/{}/{}", date.day, date.month, date.year);
6440
let revision = format!(" UEFI Revision: {}", uefi::system::uefi_revision());
6541
let firmware_vendor = format!(" Firmware Vendor: {}", uefi::system::firmware_vendor());
6642
let firmware_revision = format!(" Firmware Revision: {}", uefi::system::firmware_revision());
67-
let network_state = format!(" Network state: {:?}", net.mode().state);
6843

69-
assert!(rows >= 24);
70-
assert!(columns >= 100);
71-
72-
// Top frame //
44+
// Top frame - 1 line
45+
//==================================================================//
46+
let margin = columns - 35;
7347
stdout_text_color(&mut stdout, Color::LightRed)?;
74-
print!("┌{:─<32}┬{:─>right$}┐", "", "", right = columns - 35);
48+
print!("┌{:─<32}┬{:─>margin$}┐", "", "");
49+
//==================================================================//
7550

76-
// Info bar //
51+
// Info bar - 2 line
52+
//==================================================================//
53+
let margin = (columns - 80) / 5;
7754
print!("│ {} │", logo.next().unwrap());
7855
stdout_text_color(&mut stdout, Color::Red)?;
79-
print!(" NET: ");
56+
print!(" NET:");
8057
stdout_text_color(&mut stdout, Color::LightRed)?;
81-
print!("F1");
58+
print!("F1 ");
8259
stdout_text_color(&mut stdout, Color::Red)?;
83-
print!("{:<width$}CPU: ", "", width = (columns - 81) / 5);
60+
print!("{:<margin$}CPU:", "");
8461
stdout_text_color(&mut stdout, Color::LightRed)?;
85-
print!("F2");
62+
print!("F2 ");
8663
stdout_text_color(&mut stdout, Color::Red)?;
87-
print!("{:<width$}MEM: ", "", width = (columns - 81) / 5);
64+
print!("{:<margin$}MEM:", "");
8865
stdout_text_color(&mut stdout, Color::LightRed)?;
89-
print!("F3");
66+
print!("F3 ");
9067
stdout_text_color(&mut stdout, Color::Red)?;
91-
print!("{:<width$}PCI: ", "", width = (columns - 81) / 5);
68+
print!("{:<margin$}PCI:", "");
9269
stdout_text_color(&mut stdout, Color::LightRed)?;
93-
print!("F4");
70+
print!("F4 ");
9471
stdout_text_color(&mut stdout, Color::Red)?;
95-
print!("{:<width$}ACPI: ", "", width = (columns - 81) / 5);
72+
print!("{:<margin$}ACPI:", "");
9673
stdout_text_color(&mut stdout, Color::LightRed)?;
97-
print!("F5");
74+
print!("F5 ");
9875
stdout_text_color(&mut stdout, Color::Red)?;
99-
print!("{:<width$}HOST: ", "", width = (columns - 81) / 5);
100-
stdout_text_color(&mut stdout, Color::LightRed)?;
101-
print!("F6 │");
102-
103-
print!(
104-
"│ {} ├{:─<width$}┤",
105-
logo.next().unwrap(),
106-
"",
107-
width = columns - 35
108-
);
109-
110-
// UEFI and runtime inf lines //
76+
print!("{:<margin$}HOST:", "");
77+
stdout_text_color(&mut stdout, Color::LightRed)?;
78+
print!("F6 │");
79+
//==================================================================//
80+
81+
// Underbar - 3 line
82+
//==================================================================//
83+
let margin = columns - 35;
84+
print!("│ {} ├{:─<margin$}┤", logo.next().unwrap(), "");
85+
//==================================================================//
86+
87+
// UEFI and runtime information - 4-9 lines
88+
//==================================================================//
11189
print!("│ {} │", logo.next().unwrap());
11290
stdout_text_color(&mut stdout, Color::LightGray)?;
11391
print!("{VERSION}");
11492
stdout_text_color(&mut stdout, Color::LightRed)?;
11593
print!("{:<width$}│", "", width = columns - VERSION.len() - 35);
116-
94+
// 5
11795
print!("│ {} │", logo.next().unwrap());
11896
stdout_text_color(&mut stdout, Color::LightGray)?;
11997
print!("{resolution}");
12098
stdout_text_color(&mut stdout, Color::LightRed)?;
12199
print!("{:<width$}│", "", width = columns - resolution.len() - 35);
122-
100+
// 6
123101
print!("│ {} │", logo.next().unwrap());
124102
stdout_text_color(&mut stdout, Color::LightGray)?;
125103
print!("{date}");
126104
stdout_text_color(&mut stdout, Color::LightRed)?;
127105
print!("{:<width$}│", "", width = columns - date.len() - 35);
128-
106+
// 7
129107
print!("│ {} │", logo.next().unwrap());
130108
stdout_text_color(&mut stdout, Color::LightGray)?;
131109
print!("{revision}");
132110
stdout_text_color(&mut stdout, Color::LightRed)?;
133111
print!("{:<width$}│", "", width = columns - revision.len() - 35);
134-
112+
// 8
135113
print!("│ {} │", logo.next().unwrap());
136114
stdout_text_color(&mut stdout, Color::LightGray)?;
137115
print!("{firmware_revision}");
@@ -141,7 +119,7 @@ pub fn draw(
141119
"",
142120
width = columns - firmware_revision.len() - 35
143121
);
144-
122+
// 9
145123
print!("│ {} │", logo.next().unwrap());
146124
stdout_text_color(&mut stdout, Color::LightGray)?;
147125
print!("{firmware_vendor}");
@@ -151,18 +129,16 @@ pub fn draw(
151129
"",
152130
width = columns - firmware_vendor.len() - 35
153131
);
154-
155-
print!("│ {} │", logo.next().unwrap());
156-
stdout_text_color(&mut stdout, Color::LightGray)?;
157-
print!("{network_state}");
158-
stdout_text_color(&mut stdout, Color::LightRed)?;
132+
//==================================================================//
133+
134+
// Blank lines
135+
//==================================================================//
159136
print!(
160-
"{:<width$}│",
137+
"│ {} │{:<width$}│",
138+
logo.next().unwrap(),
161139
"",
162-
width = columns - network_state.len() - 35
140+
width = columns - 35
163141
);
164-
165-
// Blank lines //
166142
print!(
167143
"│ {} │{:<width$}│",
168144
logo.next().unwrap(),
@@ -234,12 +210,16 @@ pub fn draw(
234210
left_space = 17,
235211
right_space = columns - 35
236212
);
213+
//==================================================================//
214+
215+
// Bottom bar - 21 line
216+
//==================================================================//
237217
print!(
238218
"└{:─<32}┴{:─<right_space$}┘",
239219
"",
240220
"",
241221
right_space = columns - 35
242222
);
243-
244-
Ok(Status::SUCCESS)
223+
//==================================================================//
224+
Ok(())
245225
}

src/logic/draw/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod cpu_page;
22
pub mod mem_page;
33
pub mod menu_page;
4+
pub mod net_page;

src/logic/draw/net_page.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use uefi::{boot::ScopedProtocol, proto::network::snp::SimpleNetwork};
2+
3+
#[allow(unused)]
4+
pub fn draw(stdnet: &ScopedProtocol<SimpleNetwork>) {
5+
todo!();
6+
}

src/logic/mod.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
11
use crate::{logic::draw::menu_page, utils};
2+
use draw::{cpu_page, mem_page, net_page};
23
use info::{cpu::CpuInfo, date::Date, mem::MemInfo};
3-
use uefi::proto::{console::text::Output, network::snp::SimpleNetwork};
4+
use uefi::{
5+
proto::{
6+
console::text::{Input, Key, Output, ScanCode},
7+
network::snp::SimpleNetwork,
8+
},
9+
Status,
10+
};
411

512
mod draw;
613
mod info;
714

8-
pub fn main_eventloop() -> ! {
15+
pub fn main_eventloop() -> Status {
916
uefi::helpers::init().unwrap();
1017

1118
let cpu_info = CpuInfo::get();
1219
let date_info = Date::get().unwrap();
1320
let mem_info = MemInfo::get().unwrap();
1421

1522
let mut stdout = utils::protocols::open_scoped::<Output>().unwrap();
16-
let net = utils::protocols::open_scoped::<SimpleNetwork>().unwrap();
23+
let mut stdin = utils::protocols::open_scoped::<Input>().unwrap();
24+
let stdnet = utils::protocols::open_scoped::<SimpleNetwork>().unwrap();
1725

18-
_ = menu_page::draw(&mut stdout, &net, date_info).unwrap();
26+
// Tests with minimal (80x25) resolution
27+
// let modes_vec = stdout.modes().enumerate().collect::<Vec<_>>();
28+
// stdout.set_mode(modes_vec[0].1).unwrap();
1929

20-
loop {}
30+
menu_page::draw(&mut stdout, date_info).unwrap();
31+
32+
loop {
33+
if let Some(key) = stdin.read_key().unwrap() {
34+
match key {
35+
Key::Special(ScanCode::DELETE) => {
36+
uefi::boot::stall(100_000);
37+
break;
38+
}
39+
Key::Special(ScanCode::ESCAPE) => menu_page::draw(&mut stdout, date_info).unwrap(),
40+
Key::Special(ScanCode::FUNCTION_1) => net_page::draw(&stdnet),
41+
Key::Special(ScanCode::FUNCTION_2) => cpu_page::draw(&cpu_info),
42+
Key::Special(ScanCode::FUNCTION_3) => mem_page::draw(&mem_info),
43+
_ => {}
44+
}
45+
}
46+
}
47+
48+
Status::SUCCESS
2149
}

0 commit comments

Comments
 (0)