diff --git a/src/picowatch.py b/src/picowatch.py index e02ebfc..d13a27d 100644 --- a/src/picowatch.py +++ b/src/picowatch.py @@ -35,10 +35,11 @@ import subprocess from serial import Serial from dotenv import dotenv_values -from typing import List, Optional, Tuple, Union, Iterable +from typing import List, Optional, Tuple, Union BUFFER_SIZE: int = 256 +LISTENING_TO: str = os.getcwd() class Tab(): bordered: bool = False @@ -618,9 +619,9 @@ class Picowatch(object): queue = [] if filepath == '/': - filepath = os.getcwd().replace(os.sep, '/') + filepath = LISTENING_TO.replace(os.sep, '/') else: - filepath = os.path.join(os.getcwd(), filepath.strip('./').strip('/')).replace(os.sep, '/') + filepath = os.path.join(LISTENING_TO, filepath.strip('./').strip('/')).replace(os.sep, '/') if os.path.isfile(filepath): queue = [(filepath, os.stat(filepath)[6])] @@ -676,7 +677,7 @@ class Picowatch(object): tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception') for source, size in self.internal_ls(filepath): - destination = source.replace(os.getcwd().replace(os.sep, '/'), '').strip('/') + destination = source.replace(LISTENING_TO.replace(os.sep, '/'), '').strip('/') try: tab.line('[↑]', destination, f'{round(size / 1024, 2)} kb', self.filesystem.upload(source, destination)) @@ -691,10 +692,10 @@ class Picowatch(object): if status: for remote, size in output: if size == -1: - os.makedirs(os.path.join(os.getcwd(), remote), 777, exist_ok=True) + os.makedirs(os.path.join(LISTENING_TO, remote), 777, exist_ok=True) for remote, size in output: - destination = os.path.join(os.getcwd(), remote).replace(os.sep, '/') + destination = os.path.join(LISTENING_TO, remote).replace(os.sep, '/') if not size == -1: try: @@ -726,7 +727,7 @@ class Picowatch(object): with os.fdopen(fh, 'wb') as tmp: tmp.write(content) - subprocess.Popen(f'code --diff "{tempname}" "{os.path.join(os.getcwd(), filepath)}"', stdout=subprocess.PIPE, shell=True).communicate() + subprocess.Popen(f'code --diff "{tempname}" "{os.path.join(LISTENING_TO, filepath)}"', stdout=subprocess.PIPE, shell=True).communicate() finally: input('Press Enter to delete temp file.') os.remove(tempname) @@ -756,11 +757,14 @@ class Picowatch(object): if return_output: return changes - tab = Tab(4, 40) - tab.head('[ ]', 'Filename') + tab = Tab(4, 8, 40) + tab.head('[ ]', 'Status', 'Filename') for status, filename in changes: - tab.line('[+]' if status == 1 else '[-]', filename) + if status == 1: + tab.line('[-]', 'EDITED', filename) + else: + tab.line('[+]', 'DELETED', filename) def push(self): tab = Tab(4, 30, 15, 100) @@ -786,7 +790,7 @@ class Picowatch(object): queue.extend(self.internal_ls(filepath)) for source, size in queue: - destination = source.replace(os.getcwd().replace(os.sep, '/'), '').strip('/') + destination = source.replace(LISTENING_TO.replace(os.sep, '/'), '').strip('/') try: tab.line('[↑]', destination, f'{round(size / 1024, 2)} kb', self.filesystem.upload(source, destination)) @@ -804,7 +808,7 @@ class Picowatch(object): print(f'MicroPython File from "{filename}" created!') def test(self, filename: str): - with open(os.path.join(os.getcwd(), filename), 'r') as fh: + with open(os.path.join(LISTENING_TO, filename), 'r') as fh: self.filesystem.terminal(fh.read(), stream_output=True) def launch(self, filename: str): @@ -812,7 +816,7 @@ class Picowatch(object): print('Welcome to Picowatch Terminal') -print(f'Listening to project: {os.getcwd().replace(os.sep, "/")}/') +print(f'Listening to project: {LISTENING_TO.replace(os.sep, "/")}/') picowatch = False try: @@ -830,7 +834,7 @@ except: print('-' * 50) print(f'Connected to device: {device} and baudrate: {baudrate}') - with open(os.path.join(os.getcwd(), '.picowatch'), 'w+') as fh: + with open(os.path.join(LISTENING_TO, '.picowatch'), 'w+') as fh: fh.write(f'DEVICE = "{device}"\n') fh.write(f'BAUDRATE = {baudrate}\n') except Exception as e: @@ -845,10 +849,12 @@ while True: for message in unmessage.split('&'): match message.strip().split(' '): - case ['exit']: + case ['exit' | '\x18']: sys.exit() case ['help']: print('TODO') + case ['whois']: + print('TODO') case ['reboot']: picowatch.terminal('help()') case ['ls' | 'list', *source]: