Page 1 of 1

input() with uasyncio

Posted: Sat Mar 13, 2021 6:06 am
by f16falcona46
I have been using uasyncio to process characters from the serial console while also processing other events. However, just processing raw characters is a little inconvenient, since there's no history, no echo (by default), and no cursor handling.

My question is, is there an existing function (built-in or not) that basically acts like the builtin input() (with the cursor support, history, etc.), but is async?

Ideally something like:

Code: Select all

async def handle_user_command():
    while True:
        command = await async_input()
        #process command
If such a function doesn't exist, then is there a way I can access the readline library from within micropython and feed it individual characters?

Any information would be greatly appreciated.

Re: input() with uasyncio

Posted: Sat Mar 13, 2021 7:29 pm
by CmdrDeLiver
Peter has a wonderful tutorial for uasynio. It includes demos and I'd be surprised if one of them doesn't address your need. If you don't find a solution there, perhaps someone will have a suggestion here.

Re: input() with uasyncio

Posted: Sun Mar 14, 2021 2:51 pm
by pythoncoder
Thank you for your kind comment, but I'm afraid I don't know a way to meet the needs of @f16falcona46.

Re: input() with uasyncio

Posted: Mon Mar 15, 2021 12:48 am
by CmdrDeLiver
Thanks for all your hard work Peter.

Re: input() with uasyncio

Posted: Thu May 13, 2021 8:10 am
by f16falcona46
Thanks for the info Peter. Your tutorials are actually what got me into async programming in the first place.