tools/litex_term: add automatic check to see if we need to insert LF or not

This commit is contained in:
Florent Kermarrec 2019-08-26 18:17:43 +02:00
parent ffebd2076c
commit 0328ba7d6c
1 changed files with 10 additions and 1 deletions

View File

@ -152,6 +152,8 @@ class LiteXTerm:
signal.signal(signal.SIGINT, self.sigint)
self.sigint_time_last = 0
self.lf_insert = True
def open(self, port, baudrate):
if hasattr(self, "port"):
return
@ -259,9 +261,16 @@ class LiteXTerm:
def reader(self):
try:
c_last = 0
while self.reader_alive:
c = self.port.read()
if c == b"\r":
if c_last == b"\r":
if c == b"\n":
self.lf_insert = False
else:
self.lf_insert = True
c_last = c
if self.lf_insert and c == b"\r":
sys.stdout.buffer.write(b"\n")
else:
sys.stdout.buffer.write(c)