summaryrefslogtreecommitdiff
path: root/kernel/src/io/vga_text.rs
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-09 01:00:09 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-09 01:00:09 +0100
commitd0ecdbef0073a5516c9b7ec56d346cf9f1febd14 (patch)
treea0f9d0614468189a6888dc1c13faa1f9cacf64d4 /kernel/src/io/vga_text.rs
parent933abe8bc6f9480bcdea39c6bdd1a4e937402a06 (diff)
Create panic screen module with text buffer
Diffstat (limited to 'kernel/src/io/vga_text.rs')
-rw-r--r--kernel/src/io/vga_text.rs34
1 files changed, 10 insertions, 24 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index 281a40a..eef56bf 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -103,7 +103,7 @@ impl OStream {
pub fn put_char(&mut self, c: VgaChar) {
if c.byte == b'\n' {
self.new_line();
- } else if self.pos.0 >= WIDTH - 1 {
+ } else if self.pos.0 >= WIDTH {
self.new_line();
self.put_char(c);
} else {
@@ -158,31 +158,17 @@ impl OStream {
}
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.put_bytes(&line[..WIDTH]);
- line = &line[WIDTH..];
- n = 0;
- }
- if b == b'\n' || i == slast {
- if b != b'\n' {
- n += 1
- }
- self.set_col(((WIDTH - n) / 2) as usize);
- self.put_bytes(&line[..n]);
+ let mut line_start = 0;
+ let mut line_len = 0;
+ for (n, &c) in s.iter().enumerate() {
+ if line_len >= WIDTH || c == b'\n' || n == s.len() - 1 {
+ self.set_col((WIDTH - line_len) >> 1);
+ self.put_bytes(&s[line_start..(line_start+line_len+1)]);
self.new_line();
- if i == slast {
- return;
- }
- line = &line[(n + 1)..];
- n = 0;
+ line_start += line_len;
+ line_len = 0;
}
- n += 1;
+ line_len += 1;
}
}
}