| 1 |
|
| 2 |
"""A sample application for integrating cmd2 with external event loops. |
| 3 |
|
| 4 |
This is an example of how to use cmd2 in a way so that cmd2 doesn't own the inner event loop of your application. |
| 5 |
|
| 6 |
This opens up the possibility of registering cmd2 input with event loops, like asyncio, without occupying the main loop. |
| 7 |
""" |
| 8 |
|
| 9 |
import cmd2 |
| 10 |
|
| 11 |
|
| 12 |
class Cmd2EventBased(cmd2.Cmd): |
| 13 |
"""Basic example of how to run cmd2 without it controlling the main loop.""" |
| 14 |
|
| 15 |
def __init__(self) -> None: |
| 16 |
super().__init__() |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
if __name__ == "__main__": |
| 22 |
app = Cmd2EventBased() |
| 23 |
app.preloop() |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
app.onecmd_plus_hooks("help history") |
| 28 |
|
| 29 |
app.postloop() |