Skip to content

Instantly share code, notes, and snippets.

@quantumjim
Last active February 5, 2019 18:39
Show Gist options
  • Save quantumjim/6ec331054606fc3d676a6bae2a506b78 to your computer and use it in GitHub Desktop.
Save quantumjim/6ec331054606fc3d676a6bae2a506b78 to your computer and use it in GitHub Desktop.
import pygame
import select
import sys
class TimeoutExpired(Exception):
pass
def timed_input (prompt, timeout):
sys.stdout.write(prompt)
sys.stdout.flush()
ready, _, _ = select.select([sys.stdin], [],[], timeout)
if ready:
return sys.stdin.readline().rstrip('\n') # expect stdin to be line-buffered
raise TimeoutExpired
def get_screen (inpt):
if inpt:
screen = "\n"*10+" v \n...........^..........."
else:
screen = "\n"*10+" \n...........X..........."
return screen
inpt = None
while True:
screen = get_screen(inpt)
inpt = timed_input(screen,2)
print(inpt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment