-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve interactive console #4
Comments
I wrote up a relatively detailed question with what I want to do in the cmd2 discussions. I got some good feedback of where to start, if I want to actually use What I found in a basic study is that I can use decorators to register commands, without having to keep them in the class that subclasses def make_command(func):
"""Decorator function to add commands to the app."""
setattr(FirstApp, f"do_{func.__name__}", func)
@make_command
def new_func(self, args):
"""A function that doesn't have to be named with 'do_'"""
print("A new function is born.")
print(args) Adding functionality for pattern detection requires overriding def onecmd(
self, statement: Union[cmd2.Statement, str], *, add_to_history: bool = True
) -> bool:
# ...snip...
if func:
# ...snip...
### ADDED SECTION FOR INPUT PATTERNS
# This demo uses a check for a single pattern type (float) but could be
# sent to a more complex command or pattern parser
elif is_float(statement.command):
print(f"{float(statement.command) ** 2} {statement}")
# stop = func(statement)
return False
### END ADDED SECTION
else:
# ...snip... For functionality with an empty command, we need to override def do_empty_statement(self, args):
pass # replace with desired behavior. I'm uncomfortable having to override some obviously important functions of cmd2 to make this work. It means updates to cmd2 could break titr if I'm not careful. |
I think the main thing that I find lacking that I want to see in what is currently Looking through the source code of cmd, I can't quite figure out what makes that tick. I think it has something to do with the readline library calls. My best bet in the near term may be to take I'm still at a state where it benefits me to learn things more in depth/under the hood than it does to try to use something like cmd/cmd2 out of the box |
Noting that the above non-nice behavior seems to only happen in WSL (on this machine). Need to test if it happens in zsh/ubuntu next time I'm there. Pretty sure it happens on my work computers too. |
Well this could be easier than I thought: >>>import readline
>>> readline.__doc__
'Importing this module enables command line editing using GNU readline.' And that seems to fix it. I found this by copying the source code for I think now it's not a big jump to get datum_console to also accept tab completion using some of the functions from the |
Improve interactive console. Some nice to haves a that aren't currently implemented
Recommend doing this by building app on a modified version of cmd2.
The text was updated successfully, but these errors were encountered: