summaryrefslogtreecommitdiff
path: root/kernel/src/io/vga_text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/io/vga_text.rs')
-rw-r--r--kernel/src/io/vga_text.rs34
1 files changed, 9 insertions, 25 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index 281a40a..277db73 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,15 @@ 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;
+ let mut line_start = 0;
+ let mut line_len = 0;
+ for line in s.split(|&c| c == b'\n') {
+ if line.is_empty() { self.new_line() }
+ for chunk in line.chunks(WIDTH) {
+ self.set_col((WIDTH - chunk.len()) >> 1);
+ self.put_bytes(chunk);
+ self.new_line()
}
- 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]);
- self.new_line();
- if i == slast {
- return;
- }
- line = &line[(n + 1)..];
- n = 0;
- }
- n += 1;
}
}
}