From 3a3c7fa4cd0babe23a51fd1e50114612d2f53228 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sat, 9 Nov 2019 01:26:48 +0100 Subject: Rewrite print_centered in a more pretty way --- kernel/src/io/vga_text.rs | 13 +++++-------- 1 file 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; } } } -- cgit v1.2.3-70-g09d2