summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-09 01:26:48 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-09 01:26:48 +0100
commit3a3c7fa4cd0babe23a51fd1e50114612d2f53228 (patch)
treeb45dc2e04cf0a2276ec2670fd4186ee5332d6a42
parentb7ab3752abbe2138626e85bfb32741deece256be (diff)
Rewrite print_centered in a more pretty way
-rw-r--r--kernel/src/io/vga_text.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index eef56bf..833c191 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -160,15 +160,12 @@ impl OStream {
pub fn print_centered(&mut self, s: &[u8]) {
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();
- line_start += line_len;
- line_len = 0;
+ for chunk in s.chunks(WIDTH) {
+ for line in chunk.split(|&c| c == b'\n') {
+ self.set_col((WIDTH - line.len()) >> 1);
+ self.put_bytes(line);
+ self.new_line()
}
- line_len += 1;
}
}
}