diff --git a/hexapterygon/HexaTUI.py b/hexapterygon/HexaTUI.py index 371da3b..b64fdf6 100644 --- a/hexapterygon/HexaTUI.py +++ b/hexapterygon/HexaTUI.py @@ -16,28 +16,32 @@ def on_debloat(self, instruction, comment): self.comment = comment + def __append_instruction_text(self, text): + self.textbox_instructions.text = text + '\n' + self.textbox_instructions.text + + def on_install(self, package, output): if output == InstallState.INSTALLED: - self.textbox_instructions.text = f'│ ✓ [INSTALLED] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✓ [INSTALLED] {self.comment}') elif output == InstallState.ALREADY_INSTALLED: - self.textbox_instructions.text = f'│ ○ [INSTALLED] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ [INSTALLED] {self.comment}') else: # BLOCKED - self.textbox_instructions.text = f'│ ✗ [BLOCKED] Skipping installation\n' + self.textbox_instructions.text # TIMESTAMP TOOOOO + self.__append_instruction_text(f'│ ✗ [BLOCKED] Skipping installation') # TIMESTAMP TOOOOO self.refresh() def on_shell(self, output): # TODO: Show output only if user passes arg | if it contains Error then show x else tick maybe if not output: - self.textbox_instructions.text = f'│ ○ [SHELL] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ [SHELL] {self.comment}') self.refresh() return - self.textbox_instructions.text = f'│ ○ └─ [SHELL] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ └─ [SHELL] {self.comment}') lines = output.split('\n') if len(lines) >=2: lines = lines[:-1] for ln in lines: - self.textbox_instructions.text = f'│ ○ ├─ {ln}\n' + self.textbox_instructions.text - self.textbox_instructions.text = f'│ ○ ┌───────────────────────────────────┐\n' + self.textbox_instructions.text # long pipi energy + self.__append_instruction_text(f'│ ○ ├─ {ln}') + self.__append_instruction_text(f'│ ○ ┌───────────────────────────────────┐') # long pipi energy self.refresh() @@ -45,29 +49,29 @@ def on_downloading(self,package, i, total_length): # TODO: replace the first lin percentage = int((i)*100/total_length) steps = int((i)*30/total_length) blanks = 30-steps - if i == 1 : self.textbox_instructions.text = f"│ ○ ├─ {'━'*steps}{' '*blanks} {percentage}%\n" + self.textbox_instructions.text - lines = self.textbox_instructions.text.split('\n') + if i == 1 : self.__append_instruction_text(f"│ ○ ├─ {'━'*steps}{' '*blanks} {percentage}%") + lines = self.textbox_instructions.text.split('\n') self.textbox_instructions.text = f"│ ○ ├─ {'━'*steps}{' '*blanks} {percentage}%\n" + '\n'.join(lines[1:]) self.refresh() def on_download(self, package, output): if output == DownloadState.BEGINS: - self.textbox_instructions.text = f'│ ○ └─ [DOWNLOADING] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ └─ [DOWNLOADING] {self.comment}') elif output == DownloadState.SUCCEEDED: - self.textbox_instructions.text = f'│ ✓ ┌─ Successfully downloaded\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✓ ┌─ Successfully downloaded') elif output == DownloadState.FAILED: - self.textbox_instructions.text = f'│ ✗ ┌─ Failed to download\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✗ ┌─ Failed to download') self.refresh() def on_uninstall(self, package, output): if output == UninstallState.UNINSTALLED: - self.textbox_instructions.text = f'│ ✓ [UNINSTALLED] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✓ [UNINSTALLED] {self.comment}') elif output == UninstallState.ALREADY_UNINSTALLED: - self.textbox_instructions.text = f'│ ○ [ALREADY UNINSTALLED] {self.comment}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ [ALREADY UNINSTALLED] {self.comment}') else: - self.textbox_instructions.text = f'│ ✗ Failed to uninstall {package}\n' + self.textbox_instructions.text # TIMESTAMP TOOOOO + self.__append_instruction_text(f'│ ✗ Failed to uninstall {package}') # TIMESTAMP TOOOOO self.refresh() @@ -84,6 +88,7 @@ def __add_components(self, win, color_pair_offset): # │ Highlight(re.compile( r'(?<=│ ✗ )\[FAILED\]') , 3 , uc.A_BOLD ), Highlight(re.compile( r'[0-9]+\.') , 2 , uc.A_BOLD ), Highlight(re.compile( r'"(.*?)"') , 1 , uc.A_ITALIC), + Highlight(re.compile( r'^│(?= ░)') , 2), Highlight(re.compile( r'^│ ✓') , 5), Highlight(re.compile( r'^│ ✗') , 3), Highlight(re.compile( r'^│ ○') , 2), @@ -95,7 +100,7 @@ def __add_components(self, win, color_pair_offset): # │ Highlight(re.compile( r'(?<= ━━━━━━━━━━━━━━━━━)(━){1,8}') , 5), Highlight(re.compile( r'Successfully') , 5), Highlight(re.compile( r'(┌───────────────────────────────────┐|└─|┌─|├─)'), 1, uc.A_DIM), - Highlight(re.compile( r'(LOADING|DOWNLOADING|ALREADY UNINSTALLED|UNINSTALLED|INSTALLED|SHELL|BLOCKED)'), 1, uc.A_DIM), + Highlight(re.compile( r'(LOADING|DOWNLOADING|ALREADY UNINSTALLED|UNINSTALLED|INSTALLED|SHELL|BLOCKED|UNINSTALLS|INSTALLS|DISABLES|IMPORTANT)'), 1, uc.A_DIM), ] self.textbox_instructions.set_inline_highlight_patterns(patterns) @@ -133,9 +138,9 @@ def __exit_with_reason(self, msg): # thread exiting | https://stackoverflow.com/ def __print_result_for(self, device, output): if output: - self.textbox_instructions.text = '│ ✓ [DONE]\n' + self.textbox_instructions.text + self.__append_instruction_text('│ ✓ [DONE]') else: - self.textbox_instructions.text = f'│ ✗ [FAILED] No available debloating-list for "{device.type_identifier}" under "{device.config}"\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✗ [FAILED] No available debloating-list for "{device.type_identifier}" under "{device.config}"') self.refresh() @@ -144,7 +149,7 @@ def __get_len_of_int(self, num): return int(log10(num))+1 if not num == 0 else 1 def __validate_feedback(self, repos): # TODO: Expand if not (1 <= int(self.feedback) <= len(repos)): - self.textbox_instructions.text = f'│ ✗ [INVALID] Out of range INPUT {self.feedback}\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ✗ [INVALID] Out of range INPUT {self.feedback}') self.feedback = '' self.refresh() return True @@ -155,9 +160,9 @@ def __validate_feedback(self, repos): # TODO: Expand def __choose_available_repo_if_needed_for(self, device): # WHY SUCH A LONG NAME FOR AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA if device.locally or device.config != g.SERVER_REPO: return None # aahh whatever double checking for g.SERVER_REPO for no reason because I HAVE NO TIME TO EVEN THINK CLEARLY! F@CKING MONEY self.feedback = '' # this line was above, just in case, a reminder lol - self.textbox_instructions.text = f'│ ○ Gathering available repositories\n' + self.textbox_instructions.text + self.__append_instruction_text(f'│ ○ Gathering available repositories') self.refresh() - repos = device.get_available_repos() + repos = device.get_available_repos(get_summary=True) if not repos: return None # None because it is being handled by DeviceOverlay later and we don't want to interapt the debloating proccess of the next devices in case there is a config for them | self.__exit_with_reason(f'No available debloating-list for "{device.type_identifier}"') digit_len_of_most_started_repo = self.__get_len_of_int(repos[0][0]) i = len(repos) @@ -169,12 +174,12 @@ def __choose_available_repo_if_needed_for(self, device): # WHY SUCH A LONG NAME description_summarry += '\n│ ░ ┌─' description_summarry += '\n│ ░ ├─ '.join(repo[3]) description_summarry += '\n│ ░ └─\n' - self.__append_instruction_text(description_summarry) + self.__append_instruction_text(description_summarry) i -=1 self.label_device.text = f'⟡ Select a debloating-list for {device.type_identifier}:'; self.refresh() while not self.feedback or self.__validate_feedback(repos) : sleep(1) # I thought about it before looking into there https://superfastpython.com/thread-wait-for-result/ | feedback - no need for validation if int as of now repo = repos[int(self.feedback)-1] - self.textbox_instructions.text = f'│ ○ [LOADING] "{repo[2].strip()}"\n' + self.textbox_instructions.text; self.refresh() + self.__append_instruction_text(f'│ ○ [LOADING] "{repo[2].strip()}"\n'); self.refresh() device.config = repo[1] @@ -208,7 +213,7 @@ def __async_begin(self): if not devices: self.__exit_with_reason('No connected devices found') for device in devices: self.__reset_device_label_style() - self.__choose_available_repo_if_needed_for(device) + self.__choose_available_repo_if_needed_for(device) self.label_device.text = f'⟡ Debloating, {device.type_identifier}:'; self.refresh() self.__print_result_for(device, next(self.debloater.debloat(device))) @@ -239,7 +244,7 @@ def __reset_feedback(self): def handle_feedback_over_thread(self, event): self.escape_event_consumed = False if 47 < event < 58: - self.__feedback += uc.RCCHAR(event) + self.__feedback += uc.RCCHAR(event) self.label_info.style = uc.A_BOLD self.label_info.text = f'INPUT: {self.__feedback}' elif self.__feedback and event == 27: @@ -264,7 +269,7 @@ def handle_events(self, event, redraw_parent=True): def refresh(self): - uc.wrefresh(self.win) + uc.wrefresh(self.win) self.label_info .refresh() self.label_device .refresh() self.textbox_instructions.refresh()