Add colour config compatibility

This commit is contained in:
Maxwell 2024-07-24 14:45:40 +10:00
parent b7d080d4aa
commit c4b0d5e950

26
main.py
View File

@ -6,9 +6,7 @@ import os
import socket import socket
import subprocess import subprocess
import shutil import shutil
import curses
from datetime import datetime from datetime import datetime
from colorama import Fore
from os.path import expanduser from os.path import expanduser
# Some initial variables # Some initial variables
@ -61,6 +59,26 @@ for word in confArgList:
mashPath[pathStrIndex] = mashPath[pathStrIndex] + letter mashPath[pathStrIndex] = mashPath[pathStrIndex] + letter
except Exception: except Exception:
mashPath.append(letter) mashPath.append(letter)
if word == "colour:":
colourConf = confArgList[confArgList.index(word) + 1]
colourList = [""]
colourListIndex = 0
for letter in colourConf:
if letter == ";":
colourListIndex = colourListIndex + 1
colourList.append("")
else:
colourList[colourListIndex] = colourList[colourListIndex] + letter
colourCodes = []
for word in colourList:
if word == 'white':
colourCodes.append('\033[97m')
elif word == 'blue':
colourCodes.append('\033[34m')
elif word == 'green':
colourCodes.append('\033[32m')
elif word == 'yellow':
colourCodes.append('\033[33m')
# Write the time to the history file # Write the time to the history file
historyFile = open((expanduser("~") + "/.history.mash"), "a") historyFile = open((expanduser("~") + "/.history.mash"), "a")
historyFile.write("\n") historyFile.write("\n")
@ -79,7 +97,7 @@ def mainLoop(startDir):
while True: while True:
# Set directory and prompt for input. # Set directory and prompt for input.
os.chdir(currentDirectory) os.chdir(currentDirectory)
command = input(Fore.GREEN + user + Fore.WHITE + "@" + socket.gethostname() + Fore.BLUE + " " + currentDirectory + Fore.WHITE + " > ") command = input(colourCodes[0] + user + colourCodes[1] + "@" + colourCodes[2] + socket.gethostname() + colourCodes[3] + " " + currentDirectory + colourCodes[4] + " > ")
if command == "" : if command == "" :
mainLoop(currentDirectory) mainLoop(currentDirectory)
# Clean some things up for the argument parser. # Clean some things up for the argument parser.
@ -178,4 +196,4 @@ def mainLoop(startDir):
except KeyboardInterrupt: except KeyboardInterrupt:
print("\n") print("\n")
mainLoop(currentDirectory) mainLoop(currentDirectory)
mainLoop(initDirectory) mainLoop(initDirectory)