Question: When you press the up arrow key, you can somehow see that the display has no changes, why?
Repl link: Lexi's crypto journey - Replit
# -*- encoding: utf8 -*-
import blessings
import time
import os
import random
import readchar
import time
try:
try:
from replit import db
except ModuleNotFoundError:
db = {}
except BaseException: # Future or past versions can change ModuleNotFoundError to something else
db = {}
hotdogAscii = u"\u001b[48;5;220m\u001b[31m\u001b[1m)"
hotdogPlain = ")"
goldAscii = u"\u001b[48;5;11m\u001b[37m\u001b[1m ¡"
goldPlain = " ¡"
lexiAscii = u"\u001b[38;5;208m\u001b[1m(_\u001b[0m\u001b[48;5;214m\u001b[30m^\u001b[47m\u001b[1m..\u001b[0m\u001b[48;5;214m\u001b[30m^"
lexiPlain = "(_^..^"
try:
user = os.environ["REPL_OWNER"]
except KeyError:
try:
user = os.environ["USERNAME"] # MS-DOS and NT technology
except KeyError:
user = os.environ["USER"] # Unix, Linux, etc.
user = user.lower()
db[user] = [100.0, 100 / 4]
reset = u"\u001b[0m"
def heading(text="Lexi's crypto journey"):
text = random.choice(text.split("\n"))
print ((u"╒" + (u"═" * (len(text) + 2)) + u"╕").center(blessings.Terminal().width))
print (("[ " + text + " ]").center(blessings.Terminal().width))
print ((u"╘" + (u"═" * (len(text) + 2)) + u"╛").center(blessings.Terminal().width))
def chooseSelect(move):
move = list(move.lower())
move[0] = move[0].upper()
move = "".join(move)
global menu
menu = menu
if move == "Up":
if list(menu[0].values())[0] == True:
menu[0][list(menu[0].keys())[0]] = False
menu[-1][list(menu[-1].keys())[0]] = True
elif move == "Down":
menu = [{"Start game": True}]
def menuToCLI(menu):
res = []
for item in menu:
if list(item.values())[0] == True:
res.append("> " + list(item.keys())[0].upper())
else:
res.append(" " + list(item.keys())[0].upper())
return res
menu = [{"Start game": True}, {"Settings": False}, {"Exit": False}]
heading()
print ((" " + str(db[user][0]) + "x " + hotdogAscii + reset + "\n " + str(db[user][1]) + "x " + goldAscii + reset))
print ("")
print ("\n".join(menuToCLI(menu)))
print ("")
print ("[PRESS ENTER TO START]".center(blessings.Terminal().width))
key = repr(readchar.readkey())
if key != repr("\r"): # If the key is NOT the enter key
while key != repr("\r"): # Repeat until the key IS the enter key
os.system("clear")
heading()
print ((" " + str(db[user][0]) + "x " + hotdogAscii + reset + "\n " + str(db[user][1]) + "x " + goldAscii + reset))
print ("")
print ("\n".join(menuToCLI(menu)))
print ("")
print ("[PRESS ENTER TO START]".center(blessings.Terminal().width))
key = str(repr(readchar.readkey()))
if key == repr("\r"):
break
elif key == "\u001b[A":
chooseSelect("Up")
elif key == "\u001b[B":
chooseSelect("Down")