diff --git a/v4/main.py b/v4/main.py index 8158023..5218ff2 100644 --- a/v4/main.py +++ b/v4/main.py @@ -1,5 +1,6 @@ from memory_test import * -from memoryCLI import * +from shell import * +from shell_test import * import sys print(memory_test_generateConstPlayfield()) @@ -11,10 +12,20 @@ print(memory_test_shouldDeselectMismatchedItems_itemTwice()) print(memory_test_shouldDetectVictory()) print(memory_test_shouldHideMatchingItems()) -c = memoryCLI_createContext() -c = memoryCLI_greetUser(c) -print(c.output) +print(shell_test_exit_e()) +print(shell_test_exit_exit()) +print(shell_test_exit_q()) +print(shell_test_exit_quit()) + +c = shell_createContext() +c = shell_start(c) +if c.recentField == "output": + print(c.output) for line in sys.stdin: - ln = line.rstrip() - print(f"you entered: '{ln}'") + c.input = line.rstrip() + c = shell_processInput(c) + if c.recentField == "output": + print(c.output) + elif c.recentField == "exit": + break diff --git a/v4/shell.py b/v4/shell.py new file mode 100644 index 0000000..551b569 --- /dev/null +++ b/v4/shell.py @@ -0,0 +1,36 @@ +from shell_Context import * +from llm import * + +# Greet the user upon start +@llm_by_value +def shell_start( + c: shell_Context +) -> shell_Context: + c.output = "Shell.StartText" + c.recentField = "output" + return c +#} + +# Switch among CLI functions based on input +# +# Conditions: +# 1. User requested to quit the game +# 2. User plays the game +@llm_by_value +def shell_processInput( + c: shell_Context +) -> shell_Context: + if ( + c.input == "e" or + c.input == "exit" or + c.input == "q" or + c.input == "quit" + ): + c.exit = True + c.recentField = "exit" + return c + + c.output = "TODO Call all CLI functions, let them process game input" + c.recentField = "output" + return c +#} diff --git a/v4/shell_Context.py b/v4/shell_Context.py new file mode 100644 index 0000000..59d7d32 --- /dev/null +++ b/v4/shell_Context.py @@ -0,0 +1,8 @@ +class shell_Context: + def __init__(self): + self.exit = False + self.input = "" + self.output = "" + +def shell_createContext(): + return shell_Context() diff --git a/v4/shell_test.py b/v4/shell_test.py new file mode 100644 index 0000000..097846a --- /dev/null +++ b/v4/shell_test.py @@ -0,0 +1,54 @@ +from shell import * +from shell_Context import * + +def shell_test_exit_e( +) -> str: + c = shell_createContext() + c.input = "e" + c = shell_processInput(c) + if ( + c.recentField == "exit" + ): + return "OK: shell_exit_e" + #} + return "ERR: shell_exit_e" +#} + +def shell_test_exit_exit( +) -> str: + c = shell_createContext() + c.input = "exit" + c = shell_processInput(c) + if ( + c.recentField == "exit" + ): + return "OK: shell_exit_exit" + #} + return "ERR: shell_exit_exit" +#} + +def shell_test_exit_q( +) -> str: + c = shell_createContext() + c.input = "q" + c = shell_processInput(c) + if ( + c.recentField == "exit" + ): + return "OK: shell_exit_q" + #} + return "ERR: shell_exit_q" +#} + +def shell_test_exit_quit( +) -> str: + c = shell_createContext() + c.input = "quit" + c = shell_processInput(c) + if ( + c.recentField == "exit" + ): + return "OK: shell_exit_quit" + #} + return "ERR: shell_exit_quit" +#}