Skip to content

Commit f681577

Browse files
committed
opt(console): 优化了console的相关内容
1 parent a6c0ac8 commit f681577

File tree

5 files changed

+13
-44
lines changed

5 files changed

+13
-44
lines changed

kernel/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ glob = "0.3.0"
1010
[dependencies]
1111
ab_glyph = { version = "0.2.31", default-features = false, features = [
1212
"libm",
13-
], optional = true }
14-
libm = { version = "0.2.15", optional = true }
13+
] }
14+
libm = "0.2.15"
1515
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
1616
limine = "0.5.0"
1717
log = "0.4.27"
@@ -24,6 +24,3 @@ uart_16550 = "0.4.0"
2424
x86_64 = "0.15.2"
2525
pc-keyboard = "0.7.0"
2626
acpi = "6.0.1"
27-
28-
[features]
29-
ttf = ["dep:ab_glyph", "dep:libm"]

kernel/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ pub extern "C" fn kernel_main() -> ! {
7373
println!("Time since boot: {time}");
7474
CONSOLE.lock().cursor_show();
7575

76+
proka_kernel::output::console::select_console(proka_kernel::output::console::ConsoleType::Ttf);
77+
println!("Console after switch to Ttf");
78+
7679
loop {
7780
let mut buf = [0u8; 1];
7881
let kbd_device = {

kernel/src/output/Kconfig.toml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,9 @@ default = 0x3F8
77
desc = "Serial Port for Logging"
88
help = "The I/O port address for the serial port used for kernel logging (default 0x3F8 is COM1)."
99

10-
[[config]]
11-
name = "ENABLE_BITFONT_CONSOLE"
12-
type = "bool"
13-
default = true
14-
desc = "Enable Bitfont Console"
15-
16-
[[config]]
17-
name = "ENABLE_TTF_CONSOLE"
18-
type = "bool"
19-
default = true
20-
desc = "Enable TTF Console"
21-
feature = ["ttf"]
22-
2310
[[config]]
2411
name = "DEFAULT_CONSOLE_TYPE"
2512
type = "choice"
2613
default = "bitfont"
2714
desc = "Default Console Type"
2815
options = ["bitfont", "ttf"]
29-
depends_on = "ENABLE_BITFONT_CONSOLE || ENABLE_TTF_CONSOLE"

kernel/src/output/console/mod.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ use spin::Mutex;
44

55
use crate::graphics::Color;
66

7-
#[cfg(ENABLE_BITFONT_CONSOLE)]
87
pub mod console_bitfont;
9-
#[cfg(ENABLE_TTF_CONSOLE)]
108
pub mod console_ttf;
119

12-
#[cfg(ENABLE_BITFONT_CONSOLE)]
1310
pub use console_bitfont::BitfontConsole;
14-
#[cfg(ENABLE_TTF_CONSOLE)]
1511
pub use console_ttf::TtfConsole;
1612

1713
/// General [`Console`] trait, which defined generic APIs.
@@ -64,20 +60,13 @@ pub type ConsoleImpl<'a> = alloc::boxed::Box<dyn Console + Send + 'a>;
6460
lazy_static! {
6561
pub static ref CONSOLE: Mutex<ConsoleImpl<'static>> = {
6662
let console_type = crate::config::DEFAULT_CONSOLE_TYPE;
67-
#[cfg(ENABLE_TTF_CONSOLE)]
6863
if console_type == "ttf" {
6964
return Mutex::new(alloc::boxed::Box::new(TtfConsole::init()));
70-
}
71-
#[cfg(ENABLE_BITFONT_CONSOLE)]
72-
if console_type == "bitfont" {
65+
} else if console_type == "bitfont" {
66+
return Mutex::new(alloc::boxed::Box::new(BitfontConsole::init()));
67+
} else {
7368
return Mutex::new(alloc::boxed::Box::new(BitfontConsole::init()));
7469
}
75-
76-
// Fallback
77-
#[cfg(ENABLE_BITFONT_CONSOLE)]
78-
return Mutex::new(alloc::boxed::Box::new(BitfontConsole::init()));
79-
#[cfg(all(not(ENABLE_BITFONT_CONSOLE), ENABLE_TTF_CONSOLE))]
80-
return Mutex::new(alloc::boxed::Box::new(TtfConsole::init()));
8170
};
8271
}
8372

@@ -90,21 +79,19 @@ pub fn _print(args: fmt::Arguments) {
9079
}
9180

9281
pub enum ConsoleType {
93-
#[cfg(ENABLE_BITFONT_CONSOLE)]
9482
Bitfont,
95-
#[cfg(ENABLE_TTF_CONSOLE)]
9683
Ttf,
9784
}
9885

86+
/// Set up the current using console
9987
pub fn select_console(t: ConsoleType) {
10088
let mut console = CONSOLE.lock();
89+
90+
// Must do clear before switching console, in order to
91+
// avoid 2 console displaying problem.
92+
console.clear();
10193
*console = match t {
102-
#[cfg(ENABLE_BITFONT_CONSOLE)]
10394
ConsoleType::Bitfont => alloc::boxed::Box::new(BitfontConsole::init()),
104-
#[cfg(ENABLE_TTF_CONSOLE)]
10595
ConsoleType::Ttf => alloc::boxed::Box::new(TtfConsole::init()),
10696
};
10797
}
108-
109-
#[cfg(not(any(ENABLE_BITFONT_CONSOLE, ENABLE_TTF_CONSOLE)))]
110-
compile_error!("At least one console implementation must be enabled");

kernel/src/output/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
#[cfg(ENABLE_GRAPHICS)]
21
pub mod console;
3-
#[cfg(ENABLE_BITFONT_CONSOLE)]
42
pub use console::console_bitfont;
5-
#[cfg(ENABLE_GRAPHICS)]
63
pub mod font8x16;
7-
#[cfg(ENABLE_TTF_CONSOLE)]
84
pub use console::console_ttf;
95

106
pub mod dual;

0 commit comments

Comments
 (0)