input() with uasyncio

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
f16falcona46
Posts: 2
Joined: Sat Mar 13, 2021 5:56 am

input() with uasyncio

Post by f16falcona46 » Sat Mar 13, 2021 6:06 am

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.

User avatar
CmdrDeLiver
Posts: 27
Joined: Thu Dec 05, 2019 6:30 pm

Re: input() with uasyncio

Post by CmdrDeLiver » Sat Mar 13, 2021 7:29 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: input() with uasyncio

Post by pythoncoder » Sun Mar 14, 2021 2:51 pm

Thank you for your kind comment, but I'm afraid I don't know a way to meet the needs of @f16falcona46.
Peter Hinch
Index to my micropython libraries.

User avatar
CmdrDeLiver
Posts: 27
Joined: Thu Dec 05, 2019 6:30 pm

Re: input() with uasyncio

Post by CmdrDeLiver » Mon Mar 15, 2021 12:48 am

Thanks for all your hard work Peter.

f16falcona46
Posts: 2
Joined: Sat Mar 13, 2021 5:56 am

Re: input() with uasyncio

Post by f16falcona46 » Thu May 13, 2021 8:10 am

Thanks for the info Peter. Your tutorials are actually what got me into async programming in the first place.

Post Reply