From 75b67fa5753f33ae9ec4e0b8e65bb29834d7b412 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Fri, 10 May 2019 17:25:49 +0800 Subject: [PATCH] Replace \n to \r\n in serial driver Signed-off-by: Harry Chen --- kernel/src/drivers/serial/16550_reg.rs | 19 +++++++++++++------ kernel/src/drivers/serial/simple_uart.rs | 19 +++++++++++++------ kernel/src/drivers/serial/ti_16c550c.rs | 19 +++++++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/kernel/src/drivers/serial/16550_reg.rs b/kernel/src/drivers/serial/16550_reg.rs index 424b839..e4d7dc0 100644 --- a/kernel/src/drivers/serial/16550_reg.rs +++ b/kernel/src/drivers/serial/16550_reg.rs @@ -68,12 +68,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(()) diff --git a/kernel/src/drivers/serial/simple_uart.rs b/kernel/src/drivers/serial/simple_uart.rs index ee5c569..584fc33 100644 --- a/kernel/src/drivers/serial/simple_uart.rs +++ b/kernel/src/drivers/serial/simple_uart.rs @@ -59,12 +59,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(()) diff --git a/kernel/src/drivers/serial/ti_16c550c.rs b/kernel/src/drivers/serial/ti_16c550c.rs index 4f5b51a..e4b1973 100644 --- a/kernel/src/drivers/serial/ti_16c550c.rs +++ b/kernel/src/drivers/serial/ti_16c550c.rs @@ -68,12 +68,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(())