Metadata-Version: 2.1
Name: ph4-acmd2
Version: 1.0.0
Summary: Cmd2 extension for async programs
Home-page: https://github.com/ph4r05/ph4-acmd2
Author: Dusan Klinec
Author-email: dusan.klinec@gmail.com
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
License-File: LICENSE
Requires-Dist: cmd2==1.5.0
Provides-Extra: dev
Requires-Dist: pep8; extra == "dev"
Requires-Dist: pypandoc; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Provides-Extra: docs
Requires-Dist: Sphinx>=1.0; extra == "docs"
Requires-Dist: sphinx_rtd_theme; extra == "docs"
Requires-Dist: sphinxcontrib-programoutput; extra == "docs"

Async Cmd2
==========

Async extension to a famous
`Cmd2 <https://github.com/python-cmd2/cmd2>`__ library.

Cmd2 permanently occupies the main thread which is a problem if you plan
to receive callbacks on the main thread (e.g., by Bluetooth stack Bleak)

Pip installation
----------------

BoolTest is available via ``pip``:

::

   pip3 install ph4-acmd2

Local installation
------------------

From the local dir:

::

   pip3 install --upgrade --find-links=. .

Usage
-----

.. code:: python

   import asyncio
   import ph4acmd2

   class CmdLineApp(ph4acmd2.Cmd):
       async def main(self):
           await self.acmdloop()
           print("Cmdloop finished now")

   if __name__ == '__main__':
       app = CmdLineApp()
       loop = asyncio.get_event_loop()
       loop.set_debug(True)
       loop.run_until_complete(app.main())

Limitations
-----------

We use
`asyncio.lool.add_reader <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.add_reader>`__
to read from the stdin and process the commands thus it is not currently
possible to ue readline features such as auto-complete or ctrl-r,
UP-arrow for previous commands, etc…

Readline occupies main thread in a blocking way, so it is not compatible
with runloop model running on the main thread and executing coroutines.

In order to use readline it needs to add async support. A potential
workaround could be to access terminal in async way e.g., submit short
coroutine monitoring the terminal state to simulate readline library.
However, it is not tested.

Development
-----------

Install pre-commit hooks defined by ``.pre-commit-config.yaml``

.. code:: shell

   pip3 install -U pre-commit pytest mypy
   mypy --install-types
   pre-commit install

Auto fix

.. code:: shell

   pre-commit run --all-files

Plugin version update

.. code:: shell

   pre-commit autoupdate
