python_examples/readline/mtg.py

42 lines
1.1 KiB
Python
Raw Normal View History

2023-09-15 12:55:39 -04:00
#!/usr/bin/env python3
2023-09-16 16:51:31 -04:00
"""mtg.py
----------------
2023-09-15 12:55:39 -04:00
This module defines a command-line interface (CLI) application which allows
users to interact with a predefined list of completion options, specifically,
card names from the "Alara Reborn" set.
It leverages the `cmd` module to build the CLI and has tab-completion
functionality for adding items from the predefined list of card names.
"""
2023-08-23 11:11:51 -04:00
import cmd
completions = [
2023-09-15 12:55:39 -04:00
"Mage Slayer (Alara Reborn)",
"Magefire Wings (Alara Reborn)",
"Sages of the Anima (Alara Reborn)",
"Sanctum Plowbeast (Alara Reborn)",
"Sangrite Backlash (Alara Reborn)",
"Sanity Gnawers (Alara Reborn)",
"Sen Triplets (Alara Reborn)",
2023-08-23 11:11:51 -04:00
]
2023-09-15 12:55:39 -04:00
2023-08-23 11:11:51 -04:00
class mycmd(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
def do_quit(self, s):
return True
def do_add(self, s):
pass
def complete_add(self, text, line, begidx, endidx):
2023-09-15 12:55:39 -04:00
mline = line.partition(" ")[2]
2023-08-23 11:11:51 -04:00
offs = len(mline) - len(text)
return [s[offs:] for s in completions if s.startswith(mline)]
2023-09-15 12:55:39 -04:00
if __name__ == "__main__":
2023-08-23 11:11:51 -04:00
mycmd().cmdloop()