From 378daa6c9b54484287194dcff3d65d0b17cc0b53 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 7 May 2019 17:23:54 +0800 Subject: [PATCH] Fix bugs in Console, repr(C) is TOO EVILgit add src/! Signed-off-by: Harry Chen --- kernel/src/drivers/console/mod.rs | 12 +++++++----- kernel/src/util/escape_parser.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/src/drivers/console/mod.rs b/kernel/src/drivers/console/mod.rs index 853cce0..525f295 100644 --- a/kernel/src/drivers/console/mod.rs +++ b/kernel/src/drivers/console/mod.rs @@ -18,7 +18,6 @@ use self::fonts::{Font, Font8x16}; mod color; mod fonts; -#[repr(C)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct ConsoleChar { ascii_char: u8, @@ -28,7 +27,7 @@ pub struct ConsoleChar { impl Default for ConsoleChar { fn default() -> Self { ConsoleChar { - ascii_char: 0, + ascii_char: 0x20, attr: CharacterAttribute::default(), } } @@ -67,7 +66,9 @@ impl ConsoleBuffer { ch.attr.background.pack32(fb.color_config), ); if ch.attr.reverse { - core::mem::swap(&mut foreground, &mut background); + let temp = background; + background = foreground; + foreground = temp; } let underline_y = if ch.attr.underline { F::UNDERLINE @@ -152,8 +153,9 @@ impl Console { fn new_line(&mut self) { let attr_blank = ConsoleChar { - ascii_char: 0, - attr: self.parser.char_attribute(), + // use space as blank char, or Console shows it as '?' + ascii_char: 0x20, + attr: CharacterAttribute::default(), }; for j in self.col..self.buf.num_col { self.buf.write(self.row, j, attr_blank); diff --git a/kernel/src/util/escape_parser.rs b/kernel/src/util/escape_parser.rs index 472f437..1ae6cd5 100644 --- a/kernel/src/util/escape_parser.rs +++ b/kernel/src/util/escape_parser.rs @@ -7,7 +7,7 @@ use super::color::ConsoleColor; use heapless::consts::U8; use heapless::Vec; -#[repr(C)] + #[derive(Debug, Clone, Copy, PartialEq)] pub struct CharacterAttribute { /// foreground color