Code Monkey home page Code Monkey logo

ph4-acmd2's Introduction

Async Cmd2

Async extension to a famous 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

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 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.

ph4-acmd2's People

Contributors

ph4r05 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.