Help tab implemented and fixed small bugs

This commit is contained in:
Gino D
2023-01-07 21:02:41 +01:00
parent 074bcaa776
commit 869c2d882a
2 changed files with 46 additions and 34 deletions

View File

@@ -246,7 +246,7 @@ class Pyboard(object):
while n > 0:
self.serial.read(n)
n = self.serial.inWaiting()
n = self.serial.inWaiting()
def read_until(self, delimiter: bytes, stream_output: bool = False, show_status: bool = False) -> Optional[bytes]:
data = b''
@@ -271,22 +271,21 @@ class Pyboard(object):
time.sleep(0.001)
def boot(self):
data = b''
self.send_ctrl_c()
self.until_nothing_in_waiting()
time.sleep(.5)
if not self.read_until(self.send_ctrl_d()):
raise Exception('REPL: could not soft reboot')
data = b''
while not data.startswith(b'.\r\n>>>'):
while not data.endswith(b'\r\nMicroPython v') and not data.endswith(b'.\r\n>>>'):
if self.serial.inWaiting():
output = self.serial.read(1)
data = data[-5:] + output
sys.stdout.buffer.write(output)
data = data[-15:] + self.serial.read(1)
sys.stdout.buffer.write(data[-1:])
sys.stdout.buffer.flush()
print(' ' + ('=' * 50))
print('REPL: was interrupted')
sys.stdout.buffer.write(b'\r' + b' ' * 20 + b'\r')
def __enter__(self):
self.send_ctrl_c()
@@ -856,16 +855,29 @@ while True:
for message in unmessage.split('&'):
try:
match message.strip().split(' '):
case ['exit']:
sys.exit('Picowatch Terminal disconnected!')
case ['help']:
print('TODO')
case ['boot']:
picowatch.boot()
case ['whois']:
print('TODO')
case ['reboot']:
picowatch.terminal('help()')
case ['?' | 'help']:
print('These are common Picowatch keywords:\n')
tab = Tab(35, 70)
tab.head('Keywords', 'Description')
tab.line('uname', 'Pyboard name and version')
tab.line('exit | ctrl + c', 'Exit Picowatch Terminal')
tab.line('ctrl + c (while is running)', 'Interrupts the currently running code')
tab.line('ls [<source>]', 'List information about the file(s) on the Pyboard (the root directory by default)')
tab.line('cat <source>', 'Concatenate source code to standard output')
tab.line('rm | delete <source>', 'Delete file or directory contents on the Pyboard')
tab.line('put | upload <source>', 'Upload file or directory contents from the PC to the Pyboard')
tab.line('get | download <source>', 'Download file or directory contents from the Pyboard to the PC. Warning: this may cause file corruption.')
tab.line('diff <source>', 'Compare source code from Pyboard with source code on PC')
tab.line('mpy | compile <source>', 'Compile source file to mpy file')
tab.line('install <package-name>', 'Install a package lib')
tab.line('status', 'Show the working tree status (Git is required)')
tab.line('push', 'Update Pyboard along with associated files (Git is required)')
tab.line('? | help', 'Show keywords and their description')
tab.line('. | boot', 'Do a soft reset and run main.py (if exists) in REPL mode')
tab.line('! | test [<source>]', 'Run a script from PC on the Pyboard and print out the results in raw-REPL mode')
tab.line('!! | run [<source>]', 'Run a script on the Pyboard and print out the results in raw-REPL mode')
case ['uname']:
picowatch.terminal('import os;print(os.uname().machine, os.uname().version)')
case ['ls' | 'list', *source]:
picowatch.listing(source[0] if source else '/')
case ['cat' | 'code', source]:
@@ -876,27 +888,27 @@ while True:
picowatch.upload(source)
case ['get' | 'download', source]:
picowatch.download(source)
case ['diff' | 'compare', filename]:
picowatch.compare(filename)
case ['diff' | 'compare', source]:
picowatch.compare(source)
case ['status']:
picowatch.status(return_output=False)
case ['push']:
picowatch.push()
case ['mpy' | 'compile', filename]:
picowatch.compile(filename)
case ['mpy' | 'compile', source]:
picowatch.compile(source)
case ['install', package_name]:
pass
case ['test', filename]:
picowatch.test(filename)
case ['!']:
picowatch.test('main.py')
case ['!!']:
picowatch.launch('main.py')
print('# TODO')
case ['!' | 'test', *source]:
picowatch.test(source[0] if source else 'main.py')
case ['!!' | 'run', *source]:
picowatch.launch(source[0] if source else 'main.py')
case ['.'| 'boot']:
picowatch.boot()
case ['exit']:
sys.exit('Picowatch Terminal disconnected!')
case _:
if message.startswith('./'):
picowatch.launch(message[2:])
elif message:
print(f'"{message}" is not recognized.')
if message:
print(f'Picowatch: "{message}" does not matched any keywords. See "help" for more informations.')
except Exception as e:
print(str(e))
except (KeyboardInterrupt, EOFError):