Fixed visual bug

This commit is contained in:
Gino D
2022-12-31 15:25:19 +01:00
parent 33835ccc80
commit 01523c8d04

View File

@@ -163,7 +163,7 @@ class Pyboard(object):
self.serial.write(b'\x04') self.serial.write(b'\x04')
return b'soft reboot\r\n' return b'soft reboot\r\n'
def read_until(self, delimiter: bytes, stream_output: bool = False) -> Optional[bytes]: def read_until(self, delimiter: bytes, stream_output: bool = False, show_status: bool = False) -> Optional[bytes]:
data = self.serial.read(1) data = self.serial.read(1)
if stream_output: if stream_output:
@@ -183,7 +183,7 @@ class Pyboard(object):
if stream_output: if stream_output:
self.stdout_write_bytes(stream_data) self.stdout_write_bytes(stream_data)
data = data[-max_len:] data = data[-max_len:]
else: elif show_status:
self.loading() self.loading()
else: else:
timeout += 1 timeout += 1
@@ -216,7 +216,7 @@ class Pyboard(object):
def __exit__(self, a, b, c): def __exit__(self, a, b, c):
self.send_ctrl_b() self.send_ctrl_b()
def __terminal(self, command: str, stream_output: bool = False, catch_output: bool = True) -> Optional[str]: def __terminal(self, command: str, stream_output: bool = False, show_status: bool = True) -> Optional[str]:
command = textwrap.dedent(command) command = textwrap.dedent(command)
# send input # send input
if not isinstance(command, bytes): if not isinstance(command, bytes):
@@ -226,18 +226,17 @@ class Pyboard(object):
raise Exception('Terminal: prompt has been lost') raise Exception('Terminal: prompt has been lost')
for i in range(0, len(command), BUFFER_SIZE): for i in range(0, len(command), BUFFER_SIZE):
self.loading() if not stream_output:
self.loading()
self.serial.write(command[i: min(i + BUFFER_SIZE, len(command))]) self.serial.write(command[i: min(i + BUFFER_SIZE, len(command))])
time.sleep(0.001) time.sleep(0.001)
if not self.read_until(self.send_ok()): if not self.read_until(self.send_ok()):
raise Exception('Terminal: could not execute command') raise Exception('Terminal: could not execute command')
if not catch_output:
return
# catch output # catch output
data = self.read_until(b'\x04', stream_output=stream_output) data = self.read_until(b'\x04', stream_output=stream_output, show_status=show_status)
if not data: if not data:
raise Exception('Terminal: timeout waiting for first EOF reception') raise Exception('Terminal: timeout waiting for first EOF reception')
@@ -502,10 +501,10 @@ class FileSystem(object):
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
def terminal(self, command: str, stream_output: bool = False) -> str: def terminal(self, command: str, stream_output: bool = False, show_status: bool = True) -> str:
with self._pyboard as terminal: with self._pyboard as terminal:
try: try:
return terminal(command, stream_output=stream_output) return terminal(command, stream_output=stream_output, show_status=show_status)
except Exception as e: except Exception as e:
raise e raise e
@@ -617,7 +616,7 @@ class Picowatch(object):
filename = './' + filename filename = './' + filename
with open(filename, 'r') as fh: with open(filename, 'r') as fh:
self._fs.terminal(fh.read(), stream_output=True) self._fs.terminal(fh.read(), stream_output=True, show_status=False)