Skip to content

Commit

Permalink
✨ add async support
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 26, 2022
1 parent e58d91d commit 989a08c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion noneprompt/prompts/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,36 @@ def prompt(
return result
if default is UNDEFINED:
raise CancelledError("No answer selected!")
return default
return default # type: ignore

@overload
async def prompt_async(
self,
default: UndefinedType = UNDEFINED,
no_ansi: bool = False,
style: Optional[Style] = None,
) -> RT:
...

@overload
async def prompt_async(
self,
default: DT,
no_ansi: bool = False,
style: Optional[Style] = None,
) -> Union[DT, RT]:
...

async def prompt_async(
self,
default: Union[DT, UndefinedType] = UNDEFINED,
no_ansi: bool = False,
style: Optional[Style] = None,
) -> Union[DT, RT]:
app = self._build_application(no_ansi=no_ansi, style=style or Style([]))
result: RT = await app.run_async()
if result is not NO_ANSWER:
return result
if default is UNDEFINED:
raise CancelledError("No answer selected!")
return default # type: ignore

0 comments on commit 989a08c

Please sign in to comment.