diff options
author | natrixaeria <upezu@student.kit.edu> | 2019-11-08 17:08:56 +0100 |
---|---|---|
committer | natrixaeria <upezu@student.kit.edu> | 2019-11-08 17:08:56 +0100 |
commit | 3cdbf67de47e033110ad1250398c51e611daa1c4 (patch) | |
tree | eae32faa05e40f8cf46fdc6858afba3d2ad40cff /kernel/src/io/vga_text.rs | |
parent | bfdafd91058b91d5d4e8ab36076e05ae29355f7b (diff) |
Add centered mode to vga compatible text mode
Diffstat (limited to 'kernel/src/io/vga_text.rs')
-rw-r--r-- | kernel/src/io/vga_text.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs index 620aa32..281a40a 100644 --- a/kernel/src/io/vga_text.rs +++ b/kernel/src/io/vga_text.rs @@ -58,6 +58,7 @@ pub struct OStream { pos: (usize, usize), cursor: *mut VgaChar, state: CharState, + centered_mode: bool } impl OStream { @@ -66,6 +67,7 @@ impl OStream { pos: (0, 0), cursor: Self::at(0), state: CharState::from_colors(Color::White, Color::Black), + centered_mode: false, } } @@ -122,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); @@ -137,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; } @@ -159,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; |