Options added, fixed wordings and bugs
This commit is contained in:
@@ -62,18 +62,18 @@ class Tab():
|
|||||||
if isinstance(align_to_right, (list, tuple)):
|
if isinstance(align_to_right, (list, tuple)):
|
||||||
self.align_to_right(*align_to_right)
|
self.align_to_right(*align_to_right)
|
||||||
|
|
||||||
def head(self, *texts: str):
|
def head(self, *labels: str, border_style: str = '='):
|
||||||
self.border('=')
|
self.border(border_style)
|
||||||
self.line(*texts, bordered=False)
|
self.line(*labels, bordered=False)
|
||||||
self.border('=')
|
self.border(border_style)
|
||||||
|
|
||||||
def border(self, text: str = '-'):
|
def border(self, style: str = '-'):
|
||||||
sys.stdout.write(text * sum(self.colsize) + '\n')
|
print(style * sum(self.colsize) + '\r')
|
||||||
|
|
||||||
def align_to_right(self, *column_num: int):
|
def align_to_right(self, *column_num: int):
|
||||||
self.text_to_right = [i - 1 for i in column_num]
|
self.text_to_right = [i - 1 for i in column_num]
|
||||||
|
|
||||||
def line(self, *texts: str, bordered: bool = None):
|
def line(self, *texts: str, bordered: bool = None, border_style: str = '-'):
|
||||||
lines = {}
|
lines = {}
|
||||||
max_lines = 0
|
max_lines = 0
|
||||||
|
|
||||||
@@ -114,13 +114,13 @@ class Tab():
|
|||||||
else:
|
else:
|
||||||
output += ' ' * width
|
output += ' ' * width
|
||||||
|
|
||||||
sys.stdout.write(output + '\n')
|
print(output + '\r')
|
||||||
|
|
||||||
if bordered == False:
|
if bordered == False:
|
||||||
return
|
return
|
||||||
|
|
||||||
if bordered or self.bordered:
|
if bordered or self.bordered:
|
||||||
self.border('-')
|
self.border(border_style)
|
||||||
|
|
||||||
|
|
||||||
class Telnet:
|
class Telnet:
|
||||||
@@ -609,11 +609,27 @@ class Picowatch(object):
|
|||||||
|
|
||||||
def __init__(self, pyboard: Pyboard):
|
def __init__(self, pyboard: Pyboard):
|
||||||
self.filesystem = FileSystem(pyboard)
|
self.filesystem = FileSystem(pyboard)
|
||||||
signal.signal(signal.SIGINT, lambda sig, frame: self.interrupt())
|
signal.signal(signal.SIGINT, lambda signum, frame: self.interrupt())
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.filesystem.pyboard.boot()
|
self.filesystem.pyboard.boot()
|
||||||
|
|
||||||
|
def system(self):
|
||||||
|
self.terminal("""
|
||||||
|
import os
|
||||||
|
import gc
|
||||||
|
|
||||||
|
print('Board:', os.uname().machine, os.uname().version)
|
||||||
|
print('Free memory:', round(gc.mem_free() / 1024, 2), 'kb.')
|
||||||
|
""")
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.terminal("""
|
||||||
|
import machine
|
||||||
|
machine.soft_reset()
|
||||||
|
""")
|
||||||
|
self.interrupt()
|
||||||
|
|
||||||
def interrupt(self):
|
def interrupt(self):
|
||||||
self.filesystem.pyboard.send_ctrl_c()
|
self.filesystem.pyboard.send_ctrl_c()
|
||||||
self.filesystem.pyboard.until_nothing_in_waiting()
|
self.filesystem.pyboard.until_nothing_in_waiting()
|
||||||
@@ -678,6 +694,7 @@ class Picowatch(object):
|
|||||||
for ln in content.decode('utf-8').split('\n'):
|
for ln in content.decode('utf-8').split('\n'):
|
||||||
print(ln)
|
print(ln)
|
||||||
|
|
||||||
|
|
||||||
def upload(self, filepath: str):
|
def upload(self, filepath: str):
|
||||||
tab = Tab(4, 30, 15, 15, nb_columns=5)
|
tab = Tab(4, 30, 15, 15, nb_columns=5)
|
||||||
tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception')
|
tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception')
|
||||||
@@ -855,6 +872,12 @@ class Picowatch(object):
|
|||||||
else:
|
else:
|
||||||
print(f'Python file "{filename}" compile to .mpy')
|
print(f'Python file "{filename}" compile to .mpy')
|
||||||
|
|
||||||
|
def install(self, package_name: str):
|
||||||
|
self.terminal(f"""
|
||||||
|
import mip
|
||||||
|
mip.install('{package_name}')
|
||||||
|
""")
|
||||||
|
|
||||||
def test(self, filename: str):
|
def test(self, filename: str):
|
||||||
with open(os.path.join(LISTENING_TO, filename), 'r') as fh:
|
with open(os.path.join(LISTENING_TO, filename), 'r') as fh:
|
||||||
self.filesystem.terminal(fh.read(), stream_output=True)
|
self.filesystem.terminal(fh.read(), stream_output=True)
|
||||||
@@ -899,29 +922,34 @@ while True:
|
|||||||
try:
|
try:
|
||||||
match message.strip().split(' '):
|
match message.strip().split(' '):
|
||||||
case ['?' | 'help']:
|
case ['?' | 'help']:
|
||||||
print('These are common Picowatch keywords:\n')
|
print('These are common Picowatch keywords:')
|
||||||
tab = Tab(12, 10, 32, nb_columns=4)
|
tab = Tab(12, 10, 32, nb_columns=4)
|
||||||
tab.head('Keywords', 'Shortcut', 'Parameters', 'Description')
|
tab.head('Keywdords', 'Shortcut', 'Parameters', 'Description')
|
||||||
tab.line('help', '?', '', 'Show keywords and their description')
|
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('modules', '??', '', 'List availables modules on the Pyboard.')
|
||||||
tab.line('test', '!', '[<file>] (default: main.py)', 'Run a script from PC on the Pyboard and print out the results in raw-REPL mode')
|
tab.line('boot', '.', '', 'Perform a soft reset and run main.py (if exists) in REPL mode.')
|
||||||
tab.line('run', '!!', '[<file>] (default: main.py)', 'Run a script on the Pyboard and print out the results in raw-REPL mode')
|
tab.line('test', '!', '[<file>] (default: main.py)', 'Run a script from PC on the Pyboard and print out the results in raw-REPL mode.')
|
||||||
tab.line('ctrl + C', '', '', 'Interrupts the currently running code in REPL or raw-REPL mode')
|
tab.line('run', '!!', '[<file>] (default: main.py)', 'Run a script on the Pyboard and print out the results in raw-REPL mode.')
|
||||||
tab.line('ctrl + D', 'exit', '', 'Exit Picowatch Terminal')
|
tab.line('ctrl + C', '', '', 'Interrupts the currently running code in REPL or raw-REPL mode.')
|
||||||
tab.line('ctrl + Z', 'exit', '', 'Same as ctrl + D, Exit Picowatch Terminal')
|
tab.line('ctrl + D', 'exit', '', 'Exit Picowatch Terminal.')
|
||||||
tab.line('uname', 'os', '', 'Pyboard name and version')
|
tab.line('ctrl + Z', 'exit', '', 'Same as ctrl + D, Exit Picowatch Terminal.')
|
||||||
tab.line('scan', 'ls', '[<path>] (default: /)', 'List information about the file(s) on the Pyboard')
|
tab.line('system', 'os', '', 'Pyboard name and version.')
|
||||||
tab.line('edit', 'vim', '<file> [<use vim>]', 'Edit specified file from the PC (vim or vscode is required)')
|
tab.line('reset', 'rs', '', 'Perform a soft reset from the REPL.')
|
||||||
tab.line('source', 'cat', '<file>', 'Concatenate source code to standard output')
|
tab.line('scan', 'ls', '[<path>] (default: /)', 'List information about the file(s) on the Pyboard.')
|
||||||
tab.line('delete', 'rm', '<path>', 'Delete file or directory contents on the Pyboard')
|
tab.line('edit', 'vim', '<file> [<use vim>]', 'Edit specified file from the PC (vim or vscode is required).')
|
||||||
tab.line('upload', 'put', '<path>', 'Upload file or directory contents from the PC to the Pyboard')
|
tab.line('source', 'cat', '<file>', 'Concatenate source code to standard output.')
|
||||||
|
tab.line('delete', 'rm', '<path>', 'Delete file or directory contents on the Pyboard.')
|
||||||
|
tab.line('upload', 'put', '<path>', 'Upload file or directory contents from the PC to the Pyboard.')
|
||||||
tab.line('download', 'get', '<path>', 'Download file or directory contents from the Pyboard to the PC. Warning: this may cause file corruption.')
|
tab.line('download', 'get', '<path>', 'Download file or directory contents from the Pyboard to the PC. Warning: this may cause file corruption.')
|
||||||
tab.line('compare', 'diff', '<file> [<use vim>]', 'Compare source code from PC with source code from the Pyboard (vim or vscode is required)')
|
tab.line('compare', 'diff', '<file> [<use vim>]', 'Compare source code from PC with source code from the Pyboard (vim or vscode is required).')
|
||||||
tab.line('compile', 'mpy', '<python file>', 'Compile source file to mpy file')
|
tab.line('compile', 'mpy', '<python file>', 'Compile source file to mpy file.')
|
||||||
tab.line('status', 'mod', '', 'Show the working tree status (Git is required)')
|
tab.line('install', 'mip', '<package name>', 'Install packages from micropython-lib and from third-party sites (including GitHub) - *Network-capable boards only.')
|
||||||
tab.line('commit', 'sync', '[<message>] (default: "")', 'Synchronize Pyboard along with associated commit(s) (Git is required)')
|
tab.line('status', 'mod', '', 'Show the working tree status (Git is required).')
|
||||||
case ['os' | 'uname']:
|
tab.line('commit', 'sync', '[<message>] (default: "")', 'Synchronize Pyboard along with associated commit(s) (Git is required).')
|
||||||
picowatch.terminal('import os;print(os.uname().machine, os.uname().version)')
|
case ['??' | 'modules']:
|
||||||
|
picowatch.terminal(f'help("modules")')
|
||||||
|
case ['os' | 'system']:
|
||||||
|
picowatch.system()
|
||||||
case ['ls' | 'scan', *file]:
|
case ['ls' | 'scan', *file]:
|
||||||
picowatch.listing(file[0] if file else '/')
|
picowatch.listing(file[0] if file else '/')
|
||||||
case ['vim' | 'edit', file, *use_vim]:
|
case ['vim' | 'edit', file, *use_vim]:
|
||||||
@@ -946,13 +974,15 @@ while True:
|
|||||||
case ['mpy' | 'compile', file]:
|
case ['mpy' | 'compile', file]:
|
||||||
picowatch.compile(file)
|
picowatch.compile(file)
|
||||||
case ['mip' | 'install', package_name]:
|
case ['mip' | 'install', package_name]:
|
||||||
print('# TODO')
|
picowatch.install(package_name)
|
||||||
case ['!' | 'test', *file]:
|
case ['!' | 'test', *file]:
|
||||||
picowatch.test(file[0] if file else 'main.py')
|
picowatch.test(file[0] if file else 'main.py')
|
||||||
case ['!!' | 'run', *file]:
|
case ['!!' | 'run', *file]:
|
||||||
picowatch.launch(file[0] if file else 'main.py')
|
picowatch.launch(file[0] if file else 'main.py')
|
||||||
case ['.'| 'boot']:
|
case ['.'| 'boot']:
|
||||||
picowatch.boot()
|
picowatch.boot()
|
||||||
|
case ['rs' | 'reset']:
|
||||||
|
picowatch.reset()
|
||||||
case ['exit']:
|
case ['exit']:
|
||||||
sys.exit('Picowatch Terminal disconnected!')
|
sys.exit('Picowatch Terminal disconnected!')
|
||||||
case _:
|
case _:
|
||||||
|
|||||||
Reference in New Issue
Block a user