You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 

78 lines
2.3 KiB

#!env/bin/python3.9
import os
from termcolor import colored
import core.app as a
import apps.settings_st as settings
class Mercury:
def __init__(self):
self.apps = {"mercury":"m"}
self.app = "mercury"
self.global_commands = a.global_commands()
def get_app_name(self, filename, full = True):
without_ext = filename.replace(".py", "")
names = without_ext.split("_")
if full:
return names[0]
else:
return names[1]
def fetch_apps(self):
for file in os.listdir(a.get_path() + "apps/"):
filename = os.fsdecode(file)
if "py" in filename:
self.apps.update({self.get_app_name(filename): self.get_app_name(filename, False)})
def return_apps(self):
return {key:value for (key, value) in self.apps.items() if value != ""}
def get_app(self, app):
return colored("({}) ".format(app), settings.get("color"))
m = Mercury()
m.fetch_apps()
def global_navigator(app):
os.system('clear')
os.chdir(f"{a.get_path()}data")
while True:
arg = input(m.get_app(app))
if arg.strip() != "":
if arg in m.global_commands:
if arg == "." and app != "mercury":
global_navigator("mercury")
elif arg == "q" and app != "mercury":
global_navigator("mercury")
else:
a.handle_global_command(app, arg)
elif arg[0] == ":":
nav = arg.replace(":", "")
for app_name in m.return_apps():
if nav == app_name:
global_navigator(app_name)
elif nav == m.return_apps()[app_name]:
global_navigator(app_name)
elif arg[0] == "/":
sys_arg = arg[1:]
os.system(sys_arg)
else:
a.check_for_config(arg)
if app == "mercury":
for app_name in m.return_apps():
if arg == app_name:
global_navigator(app_name)
elif arg == m.return_apps()[app_name]:
global_navigator(app_name)
else:
a.execute(app, arg)
global_navigator("mercury")