from cli import * from cli_test import * from memory_test import * from Controller import * #from shell import * #import sys print(memory_test_deselectMismatchedItems()) print(memory_test_deselectMismatchedItems_itemTwice()) print(memory_test_detectVictory()) print(memory_test_generateConstPlayfield()) print(memory_test_hideMatchingItems()) print(memory_test_selectItem_1x()) print(memory_test_selectItem_2x()) print(memory_test_selectItem_3x()) print(cli_test_greetUser()) #print(cli_test_selectItem()) #print(cli_test_shouldPromptSelection()) ##print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin()) #print(cli_test_showHelp_h()) #print(cli_test_showHelp_help()) ctrl = Controller(memory_createContext()) ctrl.registerFunction(cli_greetUser) ctrl.registerFunction(cli_showHelp) ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'")) def printOutput(c): if c.recentField.startswith("output"): print(getattr(c, c.recentField)) ctrl.registerCallback(printOutput) # #c = shell_createContext() #c.cCLI = cli_createContext() #c.cCLI.cMemory = memory_createContext() #c.cCLI.cMemory.playfieldSize = 2 #c.cCLI.cMemory = memory_generateConstPlayfield(c.cCLI.cMemory) # #c = shell_launch(c) #print(c.output) # ctrl.set("didLaunch", True) #for line in sys.stdin: # c.input = line.rstrip() # c = shell_processInput(c) # if c.exit: # break # print(c.output) import threading import time class KeyboardThread(threading.Thread): def __init__(self, input_cbk = None, name='keyboard-input-thread'): self.input_cbk = input_cbk super(KeyboardThread, self).__init__(name=name, daemon=True) self.start() def run(self): while True: self.input_cbk(input()) #waits to get input + Return showcounter = 0 #something to demonstrate the change def my_callback(inp): #evaluate the keyboard input print('You Entered:', inp, ' Counter is at:', showcounter) #start the Keyboard thread kthread = KeyboardThread(my_callback) while True: #the normal program executes without blocking. here just counting up showcounter += 1 time.sleep(0.5)