1import sys
2
3
4def write(string: str, flush: bool=True) -> None:
5 sys.stdout.write(string)
6 if flush:
7 sys.stdout.flush()
8
9
10# up: \x1b[{n}A
11# down: \x1b[{n}B
12# right: \x1b[{n}C
13# left: \x1b[{n}D
14
15# have you noticed that in python when you hit use the arrow
16# keys in an input, you get this weird output?
17# ^[[A
18# ^[[B
19# ^[[C
20# ^[[D
21# now you'll understand why. when you type something an input,
22# it literally just prints out everything you type. if you type
23# a newline character though, it will return the text from the
24# input stream to the program. when you type a "move up", "move down",
25# or etc character, the function knows that the character is not
26# a newline character, so it just writes it to the console. this
27# is why you see stuff like ^[[A when you use the arrow keys on
28# your keyboard when typing in the input function
29
30write('type ur name below\n\nhit enter when you\'re done')
31# we will read the user's name from the input stream in between
32# the two newlines
33write('\x1b[1A') # move up one space
34write('\x1b[26D') # move left 26 spaces
35name = sys.stdin.readline() # read the user's name
36write('\x1b[1B') # move down 1 space
37write(name) # write the user's name to the console output