Loading animation added

This commit is contained in:
Gino D
2022-12-31 15:08:59 +01:00
parent 059390c3df
commit 33835ccc80

View File

@@ -36,7 +36,7 @@ from watchdog.events import PatternMatchingEventHandler
from typing import Dict, List, Optional, Tuple, Union
BUFFER_SIZE: int = 256
BUFFER_SIZE: int = 126
PRINT_STRPAD = '\t\t =>'
@@ -107,6 +107,7 @@ class Telnet:
class Pyboard(object):
i: int = 0
serial: Union[Serial, Telnet]
def __init__(self, device: str, baudrate: int = 115200, login: str = '', password: str = ''):
@@ -127,6 +128,12 @@ class Pyboard(object):
def close(self):
self.serial.close()
def loading(self) -> int:
arrows = ['', '', '', '']
sys.stdout.write(f'[∘] Loading... {arrows[self.i]}\r')
sys.stdout.flush()
self.i = (self.i + 1) % 4
def stdout_write_bytes(self, data: str):
sys.stdout.buffer.write(data.replace(b'\x04', b''))
sys.stdout.buffer.flush()
@@ -176,6 +183,8 @@ class Pyboard(object):
if stream_output:
self.stdout_write_bytes(stream_data)
data = data[-max_len:]
else:
self.loading()
else:
timeout += 1
time.sleep(0.001)
@@ -217,6 +226,7 @@ class Pyboard(object):
raise Exception('Terminal: prompt has been lost')
for i in range(0, len(command), BUFFER_SIZE):
self.loading()
self.serial.write(command[i: min(i + BUFFER_SIZE, len(command))])
time.sleep(0.001)
@@ -519,9 +529,9 @@ class Picowatch(object):
if status:
for name, size in output:
if size == -1:
print('[.]', name[1:])
print('[*]', name[1:])
else:
print('[:]', name[1:], f'({size}b)')
print('[.]', name[1:], f'({size}b)')
else:
print('[?]', remote, PRINT_STRPAD, exception)
@@ -611,7 +621,7 @@ class Picowatch(object):
print('Welcome to picowatch lib.')
print('Welcome to Picowatch Terminal')
# picowatch = False
# while not picowatch:
@@ -629,8 +639,6 @@ print('Welcome to picowatch lib.')
picowatch = Picowatch(Pyboard('COM5'))
picowatch.interupt()
# sessions = {'deleted': set(), 'modified': set()}
# def on_modified_callback(event):