summaryrefslogtreecommitdiff
path: root/kernel/src/vga_text.rs
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-10-26 00:54:05 +0200
committernatrixaeria <upezu@student.kit.edu>2019-10-26 00:54:05 +0200
commit62cce51eff15b648179a3ad8c77a0885e9394a10 (patch)
tree88664619fe5c4aea983f0cdad2c8a8ce68407e92 /kernel/src/vga_text.rs
parent983fd463b11ec1a64083f35fb09e06fb0a6e3255 (diff)
Create a kernel panic screen
Diffstat (limited to 'kernel/src/vga_text.rs')
-rw-r--r--kernel/src/vga_text.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/kernel/src/vga_text.rs b/kernel/src/vga_text.rs
index 5298da7..a292c8c 100644
--- a/kernel/src/vga_text.rs
+++ b/kernel/src/vga_text.rs
@@ -128,13 +128,40 @@ impl OStream {
pub fn set_state(&mut self, state: CharState) {
self.state = state
}
+
+ pub fn print(&mut self, s: &[u8]) {
+ for &b in s {
+ self.put_byte(b)
+ }
+ }
+
+ pub fn print_centered(&mut self, s: &[u8]) {
+ let mut line = &s[..];
+ let mut n = 0;
+ let slast = s.len() - 1;
+ for (i, &b) in s.iter().enumerate() {
+ if n >= 80 {
+ self.set_col(0);
+ self.print(&line[..80]);
+ line = &line[80..];
+ n = 0;
+ }
+ if b == b'\n' || i == slast {
+ if b != b'\n' { n += 1 }
+ self.set_col(((80 - n) / 2) as u8);
+ self.print(&line[..n]);
+ self.new_line();
+ if i == slast { return; }
+ line = &line[(n+1)..];
+ n = 0;
+ }
+ n += 1;
+ }
+ }
}
impl core::fmt::Write for OStream {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
- for &b in s.as_bytes() {
- self.put_byte(b)
- }
- Ok(())
+ Ok(self.print(s.as_bytes()))
}
}