This commit is contained in:
Dhinak G
2021-05-19 09:58:01 -04:00
parent 8f13906d2c
commit dd968a3244
5 changed files with 142 additions and 174 deletions
+18 -16
View File
@@ -2,36 +2,39 @@
from __future__ import print_function
import os
import math as m
import math
import plistlib
import subprocess
def hexswap(input_hex: str):
hex_pairs = [input_hex[i : i + 2] for i in range(0, len(input_hex), 2)]
hex_rev = hex_pairs[::-1]
hex_str = "".join(["".join(x) for x in hex_rev])
return hex_str.upper()
def header(lines):
lines = [i for i in lines if i is not None]
total_length = len(max(lines, key=len)) + 4
print("#" * (total_length))
for line in lines:
left_side = m.floor(((total_length - 2 - len(line.strip())) / 2))
left_side = math.floor(((total_length - 2 - len(line.strip())) / 2))
print("#" + " " * left_side + line.strip() + " " * (total_length - len("#" + " " * left_side + line.strip()) - 1) + "#")
print("#" * total_length)
def check_recovery():
root_partition_info = plistlib.loads(subprocess.run("diskutil info -plist /".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
if root_partition_info["VolumeName"] == "macOS Base System" and \
root_partition_info["FilesystemType"] == "apfs" and \
root_partition_info["BusProtocol"] == "Disk Image":
if root_partition_info["VolumeName"] == "macOS Base System" and root_partition_info["FilesystemType"] == "apfs" and root_partition_info["BusProtocol"] == "Disk Image":
return True
else:
return False
def cls():
# RecoveryOS doesn't support terminal clearing
if check_recovery() == False:
os.system('cls' if os.name == 'nt' else 'clear')
else:
# Default terminal window is 24 lines tall
for i in range(24):
print("")
# We only support macOS, so
print("\u001Bc")
# def menu(title, prompt, menu_options, add_quit=True, auto_number=False, in_between=[], top_level=False):
# return_option = ["Q", "Quit", None] if top_level else ["B", "Back", None]
@@ -61,7 +64,7 @@ def cls():
# menu_options[keys.index(selected.upper())][2]() if menu_options[keys.index(selected.upper())][2] else None
class TUIMenu():
class TUIMenu:
def __init__(self, title, prompt, options=None, return_number_instead_of_direct_call=False, add_quit=True, auto_number=False, in_between=None, top_level=False, loop=False):
self.title = title
self.prompt = prompt
@@ -80,8 +83,7 @@ class TUIMenu():
def start(self):
return_option = ["Q", "Quit"] if self.top_level else ["B", "Back"]
if self.add_quit and not self.added_quit:
self.add_menu_option(
return_option[1], function=None, key=return_option[0])
self.add_menu_option(return_option[1], function=None, key=return_option[0])
self.added_quit = True
while True:
@@ -120,7 +122,7 @@ class TUIMenu():
return
class TUIOnlyPrint():
class TUIOnlyPrint:
def __init__(self, title, prompt, in_between=None):
self.title = title
self.prompt = prompt