From 68cdf40a61405516f03029c299a99907da2007a9 Mon Sep 17 00:00:00 2001 From: Roland Thomas Date: Mon, 12 Feb 2024 22:53:06 -0500 Subject: [PATCH] Add example post --- content/posts/creatures.md | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 content/posts/creatures.md diff --git a/content/posts/creatures.md b/content/posts/creatures.md new file mode 100644 index 0000000..e5e8e2e --- /dev/null +++ b/content/posts/creatures.md @@ -0,0 +1,76 @@ +--- +author: "Roland Thomas Jr" +title: "Creatures" +date: "2023-08-04" +description: "Python readline" +tags: ["post"] +ShowToc: false +ShowBreadCrumbs: true +--- +creatures.py +```python +import readline + +creatures = [] + +def add_creature(): + creature = input("Enter a creature name: ") + creatures.append(creature) + print(f"{creature} added to the list of creatures.") + +def lookup_creature(): + def completer(text, state): + options = [c for c in creatures if c.startswith(text)] + if state < len(options): + return options[state] + else: + return None + + readline.set_completer(completer) + readline.parse_and_bind("tab: complete") + + print("List of creatures:") + for creature in creatures: + print(f"- {creature}") + + while True: + creature = input("Enter the name of a creature or press enter to return to the main menu: ") + if not creature: + break + elif creature in creatures: + print(f"{creature} found!") + else: + print(f"{creature} not found.") + + readline.set_completer(None) + readline.parse_and_bind("tab: ") + +def quit(): + print("Goodbye!") + exit() + +menu = { + "1": add_creature, + "2": lookup_creature, + "3": quit +} + +while True: + print("Menu:") + print("[1] Add Creature") + print("[2] Lookup Creature") + print("[3] Quit") + + choice = input("Enter your choice: ") + action = menu.get(choice) + if action: + action() + else: + print(f"{choice} is not a valid option.") +``` + +```rust +things +``` + +--- \ No newline at end of file