summaryrefslogtreecommitdiff
path: root/kernel/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/io')
-rw-r--r--kernel/src/io/vga_text.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index fddb3e1..281a40a 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -23,6 +23,7 @@ pub const WIDTH: usize = 80;
pub const HEIGHT: usize = 25;
#[derive(Clone, Copy)]
+#[repr(C)]
pub struct CharState(pub u8);
impl CharState {
@@ -41,6 +42,7 @@ impl CharState {
#[no_mangle]
#[derive(Clone, Copy)]
+#[repr(C)]
pub struct VgaChar {
pub byte: u8,
pub state: CharState,
@@ -56,6 +58,7 @@ pub struct OStream {
pos: (usize, usize),
cursor: *mut VgaChar,
state: CharState,
+ centered_mode: bool
}
impl OStream {
@@ -64,6 +67,7 @@ impl OStream {
pos: (0, 0),
cursor: Self::at(0),
state: CharState::from_colors(Color::White, Color::Black),
+ centered_mode: false,
}
}
@@ -120,6 +124,10 @@ impl OStream {
}
}
+ pub fn set_centered(&mut self, b: bool) {
+ self.centered_mode = b
+ }
+
pub fn new_line(&mut self) {
if self.pos.1 >= HEIGHT - 1 {
self.set_col(0);
@@ -135,20 +143,29 @@ impl OStream {
self.state = state
}
- pub fn print(&mut self, s: &[u8]) {
+ pub fn put_bytes(&mut self, s: &[u8]) {
for &b in s {
self.put_byte(b)
}
}
+ pub fn print(&mut self, s: &[u8]) {
+ if self.centered_mode {
+ self.print_centered(s)
+ } else {
+ self.put_bytes(s)
+ }
+ }
+
pub fn print_centered(&mut self, s: &[u8]) {
let mut line = &s[..];
let mut n = 0;
+ if s.len() == 0 { return; }
let slast = s.len() - 1;
for (i, &b) in s.iter().enumerate() {
if n >= WIDTH {
self.set_col(0);
- self.print(&line[..WIDTH]);
+ self.put_bytes(&line[..WIDTH]);
line = &line[WIDTH..];
n = 0;
}
@@ -157,7 +174,7 @@ impl OStream {
n += 1
}
self.set_col(((WIDTH - n) / 2) as usize);
- self.print(&line[..n]);
+ self.put_bytes(&line[..n]);
self.new_line();
if i == slast {
return;