Help tab implemented and fixed small bugs
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
python "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/src/picowatch.py" $(pwd)
|
python "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/src/picowatch.py"
|
||||||
@@ -246,7 +246,7 @@ class Pyboard(object):
|
|||||||
|
|
||||||
while n > 0:
|
while n > 0:
|
||||||
self.serial.read(n)
|
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]:
|
def read_until(self, delimiter: bytes, stream_output: bool = False, show_status: bool = False) -> Optional[bytes]:
|
||||||
data = b''
|
data = b''
|
||||||
@@ -271,22 +271,21 @@ class Pyboard(object):
|
|||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
|
data = b''
|
||||||
self.send_ctrl_c()
|
self.send_ctrl_c()
|
||||||
self.until_nothing_in_waiting()
|
self.until_nothing_in_waiting()
|
||||||
|
time.sleep(.5)
|
||||||
|
|
||||||
if not self.read_until(self.send_ctrl_d()):
|
if not self.read_until(self.send_ctrl_d()):
|
||||||
raise Exception('REPL: could not soft reboot')
|
raise Exception('REPL: could not soft reboot')
|
||||||
|
|
||||||
data = b''
|
while not data.endswith(b'\r\nMicroPython v') and not data.endswith(b'.\r\n>>>'):
|
||||||
while not data.startswith(b'.\r\n>>>'):
|
|
||||||
if self.serial.inWaiting():
|
if self.serial.inWaiting():
|
||||||
output = self.serial.read(1)
|
data = data[-15:] + self.serial.read(1)
|
||||||
data = data[-5:] + output
|
sys.stdout.buffer.write(data[-1:])
|
||||||
sys.stdout.buffer.write(output)
|
|
||||||
sys.stdout.buffer.flush()
|
sys.stdout.buffer.flush()
|
||||||
|
|
||||||
print(' ' + ('=' * 50))
|
sys.stdout.buffer.write(b'\r' + b' ' * 20 + b'\r')
|
||||||
print('REPL: was interrupted')
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.send_ctrl_c()
|
self.send_ctrl_c()
|
||||||
@@ -856,16 +855,29 @@ while True:
|
|||||||
for message in unmessage.split('&'):
|
for message in unmessage.split('&'):
|
||||||
try:
|
try:
|
||||||
match message.strip().split(' '):
|
match message.strip().split(' '):
|
||||||
case ['exit']:
|
case ['?' | 'help']:
|
||||||
sys.exit('Picowatch Terminal disconnected!')
|
print('These are common Picowatch keywords:\n')
|
||||||
case ['help']:
|
tab = Tab(35, 70)
|
||||||
print('TODO')
|
tab.head('Keywords', 'Description')
|
||||||
case ['boot']:
|
tab.line('uname', 'Pyboard name and version')
|
||||||
picowatch.boot()
|
tab.line('exit | ctrl + c', 'Exit Picowatch Terminal')
|
||||||
case ['whois']:
|
tab.line('ctrl + c (while is running)', 'Interrupts the currently running code')
|
||||||
print('TODO')
|
tab.line('ls [<source>]', 'List information about the file(s) on the Pyboard (the root directory by default)')
|
||||||
case ['reboot']:
|
tab.line('cat <source>', 'Concatenate source code to standard output')
|
||||||
picowatch.terminal('help()')
|
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]:
|
case ['ls' | 'list', *source]:
|
||||||
picowatch.listing(source[0] if source else '/')
|
picowatch.listing(source[0] if source else '/')
|
||||||
case ['cat' | 'code', source]:
|
case ['cat' | 'code', source]:
|
||||||
@@ -876,27 +888,27 @@ while True:
|
|||||||
picowatch.upload(source)
|
picowatch.upload(source)
|
||||||
case ['get' | 'download', source]:
|
case ['get' | 'download', source]:
|
||||||
picowatch.download(source)
|
picowatch.download(source)
|
||||||
case ['diff' | 'compare', filename]:
|
case ['diff' | 'compare', source]:
|
||||||
picowatch.compare(filename)
|
picowatch.compare(source)
|
||||||
case ['status']:
|
case ['status']:
|
||||||
picowatch.status(return_output=False)
|
picowatch.status(return_output=False)
|
||||||
case ['push']:
|
case ['push']:
|
||||||
picowatch.push()
|
picowatch.push()
|
||||||
case ['mpy' | 'compile', filename]:
|
case ['mpy' | 'compile', source]:
|
||||||
picowatch.compile(filename)
|
picowatch.compile(source)
|
||||||
case ['install', package_name]:
|
case ['install', package_name]:
|
||||||
pass
|
print('# TODO')
|
||||||
case ['test', filename]:
|
case ['!' | 'test', *source]:
|
||||||
picowatch.test(filename)
|
picowatch.test(source[0] if source else 'main.py')
|
||||||
case ['!']:
|
case ['!!' | 'run', *source]:
|
||||||
picowatch.test('main.py')
|
picowatch.launch(source[0] if source else 'main.py')
|
||||||
case ['!!']:
|
case ['.'| 'boot']:
|
||||||
picowatch.launch('main.py')
|
picowatch.boot()
|
||||||
|
case ['exit']:
|
||||||
|
sys.exit('Picowatch Terminal disconnected!')
|
||||||
case _:
|
case _:
|
||||||
if message.startswith('./'):
|
if message:
|
||||||
picowatch.launch(message[2:])
|
print(f'Picowatch: "{message}" does not matched any keywords. See "help" for more informations.')
|
||||||
elif message:
|
|
||||||
print(f'"{message}" is not recognized.')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
|||||||
Reference in New Issue
Block a user