From 33835ccc8043f7aac01b5fe674ba6410ad6237f0 Mon Sep 17 00:00:00 2001 From: Gino D Date: Sat, 31 Dec 2022 15:08:59 +0100 Subject: [PATCH] Loading animation added --- picowatch_d/picowatch.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/picowatch_d/picowatch.py b/picowatch_d/picowatch.py index 1f3e913..1c59014 100644 --- a/picowatch_d/picowatch.py +++ b/picowatch_d/picowatch.py @@ -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):