colorized warning, success and error messages
This commit is contained in:
@@ -56,7 +56,7 @@ class MenuHelper:
|
||||
# check if choice is in menu
|
||||
match self.start_menu[choice]:
|
||||
case "Exit":
|
||||
print('Exiting system')
|
||||
print(f"{utilityHelper.blinkMessage('Exiting system')}")
|
||||
exit()
|
||||
|
||||
case "Explore the Blockchain":
|
||||
@@ -69,7 +69,7 @@ class MenuHelper:
|
||||
if logged_in:
|
||||
print(f'Welcome {self.user.username}')
|
||||
return
|
||||
print("Login failed")
|
||||
print(f"{utilityHelper.errorMessage('Login failed')}")
|
||||
self.user = None
|
||||
|
||||
case "Sign up":
|
||||
@@ -77,19 +77,19 @@ class MenuHelper:
|
||||
registered = self.user.register()
|
||||
utilityHelper.clearScreen()
|
||||
if registered:
|
||||
print("Registration successful")
|
||||
print(f"{utilityHelper.successMessage('Registration successful')}")
|
||||
new_tx = Tx()
|
||||
new_tx.createRewardTransaction(self.user.public_ser, self.user.private_ser, "SIGNUP")
|
||||
if new_tx != False and new_tx.is_valid():
|
||||
print("Received sign up bonus")
|
||||
print(f"{utilityHelper.blinkMessage('Received sign up bonus')}")
|
||||
utilityHelper.saveFile("../data/transaction_pool.dat", new_tx)
|
||||
return
|
||||
print("Transaction is invalid")
|
||||
print("Registration failed")
|
||||
print(f"{utilityHelper.errorMessage('Transaction is invalid')}")
|
||||
print(f"{utilityHelper.errorMessage('Registration failed')}")
|
||||
self.user = None
|
||||
|
||||
case _:
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
|
||||
def runUserMainMenu(self):
|
||||
utilityHelper.loginStartup(self)
|
||||
@@ -102,7 +102,7 @@ class MenuHelper:
|
||||
# check if choice is in menu
|
||||
match self.user_main_menu[choice]:
|
||||
case "Exit":
|
||||
print('Exiting system')
|
||||
print(f"{utilityHelper.blinkMessage('Exiting system')}")
|
||||
exit()
|
||||
|
||||
case "Log out":
|
||||
@@ -116,7 +116,7 @@ class MenuHelper:
|
||||
self.runUserBlockchainMenu()
|
||||
|
||||
case _:
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
|
||||
def runUserBlockchainMenu(self):
|
||||
while(self.user):
|
||||
@@ -142,10 +142,10 @@ class MenuHelper:
|
||||
case "Transfer coins":
|
||||
new_tx = transactionHelper.transaction(self)
|
||||
if new_tx != False and new_tx.is_valid():
|
||||
print("Transaction is valid")
|
||||
print(f"{utilityHelper.successMessage('Transaction is valid')}")
|
||||
utilityHelper.saveFile("../data/transaction_pool.dat", new_tx)
|
||||
continue
|
||||
print("Transaction is invalid")
|
||||
print(f"{utilityHelper.errorMessage('Transaction is invalid')}")
|
||||
|
||||
|
||||
case "Check balance":
|
||||
@@ -156,7 +156,7 @@ class MenuHelper:
|
||||
case "Check the pool":
|
||||
transactions = utilityHelper.loadFile("../data/transaction_pool.dat")
|
||||
if len(transactions) == 0:
|
||||
print("Transaction pool is empty")
|
||||
print(f"{utilityHelper.warningMessage('Transaction pool is empty')}")
|
||||
continue
|
||||
x = 0
|
||||
for transaction in transactions:
|
||||
@@ -169,7 +169,7 @@ class MenuHelper:
|
||||
blockHelper.createBlock(self)
|
||||
|
||||
case _:
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
|
||||
def runUserSettingsMenu(self):
|
||||
while(self.user):
|
||||
@@ -197,7 +197,7 @@ class MenuHelper:
|
||||
self.user = None
|
||||
|
||||
case _:
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
|
||||
def getMenuInput(self, menu):
|
||||
self.printMenu(menu)
|
||||
@@ -206,12 +206,12 @@ class MenuHelper:
|
||||
choice = int(input(">>: "))
|
||||
except:
|
||||
utilityHelper.clearScreen()
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
return None
|
||||
|
||||
if choice >= len(menu):
|
||||
utilityHelper.clearScreen()
|
||||
print("Wrong input, try again")
|
||||
print(f"{utilityHelper.warningMessage('Wrong input, try again')}")
|
||||
return None
|
||||
utilityHelper.clearScreen()
|
||||
|
||||
|
@@ -13,6 +13,7 @@ class bcolors:
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
BLINK = '\033[5m'
|
||||
|
||||
def computeHash(data):
|
||||
hash = hashlib.sha256()
|
||||
@@ -57,27 +58,29 @@ def loginStartup(self):
|
||||
blockHelper.validateMinedBlock(self)
|
||||
# TODO - check if there are any notifcations
|
||||
|
||||
def printError(text):
|
||||
print(f"{bcolors.FAIL}{text}{bcolors.ENDC}")
|
||||
def errorMessage(text):
|
||||
return bcolors.FAIL + text + bcolors.ENDC
|
||||
|
||||
def printSuccess(text):
|
||||
print(f"{bcolors.OKGREEN}{text}{bcolors.ENDC}")
|
||||
def successMessage(text):
|
||||
return bcolors.OKGREEN + text + bcolors.ENDC
|
||||
|
||||
def printWarning(text):
|
||||
print(f"{bcolors.WARNING}{text}{bcolors.ENDC}")
|
||||
def warningMessage(text):
|
||||
return bcolors.WARNING + text + bcolors.ENDC
|
||||
|
||||
def printInfo(text):
|
||||
print(f"{bcolors.OKBLUE}{text}{bcolors.ENDC}")
|
||||
def infoMessage(text):
|
||||
return bcolors.OKBLUE + text + bcolors.ENDC
|
||||
|
||||
def printBold(text):
|
||||
print(f"{bcolors.BOLD}{text}{bcolors.ENDC}")
|
||||
def boldMessage(text):
|
||||
return bcolors.BOLD + text + bcolors.ENDC
|
||||
|
||||
def printUnderline(text):
|
||||
print(f"{bcolors.UNDERLINE}{text}{bcolors.ENDC}")
|
||||
def underlineMessage(text):
|
||||
return bcolors.UNDERLINE + text + bcolors.ENDC
|
||||
|
||||
def printHeader(text):
|
||||
print(f"{bcolors.HEADER}{text}{bcolors.ENDC}")
|
||||
def headerMessage(text):
|
||||
return bcolors.HEADER + text + bcolors.ENDC
|
||||
|
||||
def blinkMessage(text):
|
||||
return bcolors.BLINK + text + bcolors.ENDC
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user