From e3af3b8ab9d44e6100195dc912bac87a7dd9a0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sat, 4 May 2024 23:19:31 +0300 Subject: [PATCH] d --- v4/main.py | 23 ++++++++++++++----- v4/shell.py | 36 ++++++++++++++++++++++++++++++ v4/shell_Context.py | 8 +++++++ v4/shell_test.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 v4/shell.py create mode 100644 v4/shell_Context.py create mode 100644 v4/shell_test.py 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" +#}