d
This commit is contained in:
113
v4/cli.py
113
v4/cli.py
@@ -46,6 +46,62 @@ def cli_greetUser(
|
||||
return c
|
||||
#}
|
||||
|
||||
# Ask user to select second item to have a pair of selected items
|
||||
@llm_by_value
|
||||
def cli_promptSecondItemSelection(
|
||||
c: memory_Context
|
||||
) -> memory_Context:
|
||||
if (
|
||||
c.recentField == "selectedItems" and
|
||||
len(c.selectedItems) == 1
|
||||
):
|
||||
c.outputPromptSelection = "Select the second item now:"
|
||||
c.recentField = "outputPromptSelection"
|
||||
return c
|
||||
#}
|
||||
c.recentField = "none"
|
||||
return c
|
||||
#}
|
||||
|
||||
# Report matched items
|
||||
@llm_by_value
|
||||
def cli_reportMatchedItems(
|
||||
c: memory_Context
|
||||
) -> memory_Context:
|
||||
if (
|
||||
c.recentField == "hiddenItems"
|
||||
):
|
||||
c.outputMatchedItems = "Items matched! Go on:"
|
||||
c.recentField = "outputMatchedItems"
|
||||
return c
|
||||
#}
|
||||
c.recentField = "none"
|
||||
return c
|
||||
#}
|
||||
|
||||
|
||||
# Select item
|
||||
#
|
||||
# Conditions:
|
||||
# 1. Id is digit
|
||||
@llm_by_value
|
||||
def cli_selectItem(
|
||||
c: memory_Context
|
||||
) -> memory_Context:
|
||||
if (
|
||||
c.recentField == "input" and
|
||||
c.input.isdigit()
|
||||
):
|
||||
# CLI ids start with 1 while memory module has ids starting with 0
|
||||
# Convert CLI id to memory id
|
||||
c.selectedId = int(c.input) - 1
|
||||
c.recentField = "selectedId"
|
||||
return c
|
||||
#}
|
||||
c.recentField = "none"
|
||||
return c
|
||||
#}
|
||||
|
||||
# Show help (aka commands)
|
||||
#
|
||||
# Conditions:
|
||||
@@ -77,63 +133,6 @@ def cli_showHelp(
|
||||
return c
|
||||
#}
|
||||
|
||||
## Select item
|
||||
##
|
||||
## Conditions:
|
||||
## 1. Id is digit, in bounds and not hidden
|
||||
#@llm_by_value
|
||||
#def cli_selectItem(
|
||||
# c: cli_Context
|
||||
#) -> cli_Context:
|
||||
# if (
|
||||
# c.input.isdigit()
|
||||
# ):
|
||||
# # User ids start with 1 while memory module has ids starting with 0
|
||||
# # Convert cli item id to memory item id
|
||||
# c.cMemory.selectedId = int(c.input) - 1
|
||||
# c.cMemory = memory_selectItem(c.cMemory)
|
||||
# c.recentField = "cMemory"
|
||||
# return c
|
||||
# #}
|
||||
# c.recentField = "none"
|
||||
# return c
|
||||
##}
|
||||
#
|
||||
## Ask user to select another item to have a pair of selected items
|
||||
#@llm_by_value
|
||||
#def cli_shouldPromptSelection(
|
||||
# c: cli_Context
|
||||
#) -> cli_Context:
|
||||
# if (
|
||||
# c.recentField == "cMemory" and
|
||||
# c.cMemory.recentField == "selectedItems" and
|
||||
# len(c.cMemory.selectedItems) == 1
|
||||
# ):
|
||||
# c.outputPromptSelection = "Select the second item now:"
|
||||
# c.recentField = "outputPromptSelection"
|
||||
# return c
|
||||
# #}
|
||||
# c.recentField = "none"
|
||||
# return c
|
||||
##}
|
||||
#
|
||||
## Report matched items
|
||||
#@llm_by_value
|
||||
#def cli_shouldReportMatchedItems(
|
||||
# c: cli_Context
|
||||
#) -> cli_Context:
|
||||
# if (
|
||||
# c.recentField == "cMemory" and
|
||||
# c.cMemory.recentField == "hiddenItems"
|
||||
# ):
|
||||
# c.outputMatchedItems = "Items matched! Go on:"
|
||||
# c.recentField = "outputMatchedItems"
|
||||
# return c
|
||||
# #}
|
||||
# c.recentField = "none"
|
||||
# return c
|
||||
##}
|
||||
#
|
||||
## Report mismatched items
|
||||
#@llm_by_value
|
||||
#def cli_shouldReportMismatchedItems(
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "cli_Context.h"
|
||||
|
||||
cli_Context cli_createContext() {
|
||||
return cli_Context();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef cli_Context_HEADER
|
||||
#define cli_Context_HEADER
|
||||
|
||||
struct cli_Context {
|
||||
std::string input = "";
|
||||
std::string outputGreeting = "";
|
||||
std::string outputHelp = "";
|
||||
std::string recentField = "none";
|
||||
};
|
||||
|
||||
cli_Context cli_createContext();
|
||||
|
||||
#endif // cli_Context_HEADER
|
||||
@@ -1,12 +0,0 @@
|
||||
class cli_Context:
|
||||
def __init__(self):
|
||||
self.cMemory = None
|
||||
self.input = ""
|
||||
self.outputGreeting = ""
|
||||
self.outputHelp = ""
|
||||
self.recentField = "none"
|
||||
self.outputMatchedItems = ""
|
||||
self.outputMismatchedItems = ""
|
||||
|
||||
def cli_createContext():
|
||||
return cli_Context()
|
||||
@@ -72,6 +72,61 @@ def cli_test_greetUser(
|
||||
return "ERR: cli_greetUser"
|
||||
#}
|
||||
|
||||
def cli_test_promptSecondItemSelection(
|
||||
) -> str:
|
||||
c = memory_createContext()
|
||||
c.input = "1"
|
||||
c.recentField = "input"
|
||||
c = cli_selectItem(c)
|
||||
c = memory_selectItem(c)
|
||||
c = cli_promptSecondItemSelection(c)
|
||||
if (
|
||||
c.recentField == "outputPromptSelection"
|
||||
):
|
||||
return "OK: cli_promptSecondItemSelection"
|
||||
#}
|
||||
return "ERR: cli_promptSecondItemSelection"
|
||||
#}
|
||||
|
||||
def cli_test_reportMatchedItems(
|
||||
) -> str:
|
||||
c = memory_createContext()
|
||||
c.playfieldSize = 2
|
||||
c.recentField = "playfieldSize"
|
||||
c = memory_generateConstPlayfield(c)
|
||||
c.input = "1"
|
||||
c.recentField = "input"
|
||||
c = cli_selectItem(c)
|
||||
c = memory_selectItem(c)
|
||||
c.input = "2"
|
||||
c.recentField = "input"
|
||||
c = cli_selectItem(c)
|
||||
c = memory_selectItem(c)
|
||||
c = memory_hideMatchingItems(c)
|
||||
c = cli_reportMatchedItems(c)
|
||||
if (
|
||||
c.recentField == "outputMatchedItems"
|
||||
):
|
||||
return "OK: cli_reportMatchedItems"
|
||||
#}
|
||||
return "ERR: cli_reportMatchedItems"
|
||||
#}
|
||||
|
||||
def cli_test_selectItem(
|
||||
) -> str:
|
||||
c = memory_createContext()
|
||||
c.input = "1"
|
||||
c.recentField = "input"
|
||||
c = cli_selectItem(c)
|
||||
if (
|
||||
c.recentField == "selectedId" and
|
||||
c.selectedId == 0
|
||||
):
|
||||
return "OK: cli_selectItem"
|
||||
#}
|
||||
return "ERR: cli_selectItem"
|
||||
#}
|
||||
|
||||
def cli_test_showHelp_h(
|
||||
) -> str:
|
||||
c = memory_createContext()
|
||||
@@ -100,36 +155,7 @@ def cli_test_showHelp_help(
|
||||
return "ERR: cli_showHelp_help"
|
||||
#}
|
||||
|
||||
#def cli_test_selectItem(
|
||||
#) -> str:
|
||||
# c = cli_createContext()
|
||||
# c.cMemory = memory_createContext()
|
||||
# c.input = "1"
|
||||
# c = cli_selectItem(c)
|
||||
# if (
|
||||
# c.recentField == "cMemory" and
|
||||
# c.cMemory.recentField == "selectedItems"
|
||||
# ):
|
||||
# return "OK: cli_selectItem"
|
||||
# #}
|
||||
# return "ERR: cli_selectItem"
|
||||
##}
|
||||
#
|
||||
#def cli_test_shouldPromptSelection(
|
||||
#) -> str:
|
||||
# c = cli_createContext()
|
||||
# c.cMemory = memory_createContext()
|
||||
# c.input = "1"
|
||||
# c = cli_selectItem(c)
|
||||
# c = cli_shouldPromptSelection(c)
|
||||
# if (
|
||||
# c.recentField == "outputPromptSelection"
|
||||
# ):
|
||||
# return "OK: cli_shouldPromptSelection"
|
||||
# #}
|
||||
# return "ERR: cli_shouldPromptSelection"
|
||||
##}
|
||||
#
|
||||
|
||||
#def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin(
|
||||
#) -> str:
|
||||
# c = cli_createContext()
|
||||
|
||||
26
v4/main.py
26
v4/main.py
@@ -20,15 +20,23 @@ print(cli_test_exit_quit())
|
||||
print(cli_test_greetUser())
|
||||
print(cli_test_showHelp_h())
|
||||
print(cli_test_showHelp_help())
|
||||
#print(cli_test_selectItem())
|
||||
#print(cli_test_shouldPromptSelection())
|
||||
##print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin())
|
||||
print(cli_test_selectItem())
|
||||
print(cli_test_promptSecondItemSelection())
|
||||
print(cli_test_reportMatchedItems())
|
||||
|
||||
|
||||
ctrl = Controller(memory_createContext())
|
||||
ctrl.registerFunction(cli_exit)
|
||||
ctrl.registerFunction(cli_greetUser)
|
||||
ctrl.registerFunction(cli_promptSecondItemSelection)
|
||||
ctrl.registerFunction(cli_reportMatchedItems)
|
||||
ctrl.registerFunction(cli_selectItem)
|
||||
ctrl.registerFunction(cli_showHelp)
|
||||
ctrl.registerFunction(memory_deselectMismatchedItems)
|
||||
ctrl.registerFunction(memory_detectVictory)
|
||||
ctrl.registerFunction(memory_generateConstPlayfield)
|
||||
ctrl.registerFunction(memory_hideMatchingItems)
|
||||
ctrl.registerFunction(memory_selectItem)
|
||||
|
||||
def printOutput(c):
|
||||
if c.recentField.startswith("output"):
|
||||
@@ -37,18 +45,8 @@ ctrl.registerCallback(printOutput)
|
||||
#ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'"))
|
||||
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))
|
||||
|
||||
#
|
||||
#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)
|
||||
ctrl.set("playfieldSize", 2)
|
||||
|
||||
for line in sys.stdin:
|
||||
ln = line.rstrip()
|
||||
|
||||
@@ -8,6 +8,7 @@ class memory_Context:
|
||||
self.outputHelp = ""
|
||||
self.outputMatchedItems = ""
|
||||
self.outputMismatchedItems = ""
|
||||
self.outputPromptSelection = ""
|
||||
self.playfieldItems = {}
|
||||
self.playfieldSize = 0
|
||||
self.recentField = "none"
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "shell_Context.h"
|
||||
|
||||
shell_Context shell_createContext() {
|
||||
return shell_Context();
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "cli_Context.h"
|
||||
|
||||
#ifndef shell_Context_HEADER
|
||||
#define shell_Context_HEADER
|
||||
|
||||
struct shell_Context {
|
||||
cli_Context cCLI;
|
||||
bool exit = false;
|
||||
std::string input = "";
|
||||
std::string output = "";
|
||||
};
|
||||
|
||||
shell_Context shell_createContext();
|
||||
|
||||
#endif // shell_Context_HEADER
|
||||
@@ -1,9 +0,0 @@
|
||||
class shell_Context:
|
||||
def __init__(self):
|
||||
self.cCLI = None
|
||||
self.exit = False
|
||||
self.input = ""
|
||||
self.output = ""
|
||||
|
||||
def shell_createContext():
|
||||
return shell_Context()
|
||||
Reference in New Issue
Block a user