I have a sort-of 'hacked' CLI I'm trying to build. I have a global input in a while loop, and the user can perpetually enter 'commands' to produce various results. I'm wondering, how can I let the user press the Up-Arrow (as you would in a basic terminal) to put the contents of the latest entered command? The code will improve context.
while True:
arg = input("(user) ~ ")
if arg == "joke":
print("There's a band called 1023MB. They haven't had any gigs yet.")
elif arg == "hi":
print("Hello.")
# If arg == up-arrow: getLatestCommand()
# I'm not quite sure how to implement this...
Example scenario:
(user) ~ joke
There's a band called 1023MB. They haven't had any gigs yet.
(user) ~ UP-ARROW PRESS
(user) ~ joke
I attempted to use the keyboard module in Python, but I was unable to get rid of this ugly thing: whenever I press the up arrow on mac in a Python input, it forces output of the following, "^[[A" which is annoying.