Add UserInputAction, coerce ActionFactoryAction to be async, add custom tables for MenuAction, Change Exit Command to use X
This commit is contained in:
@ -9,6 +9,7 @@ commands:
|
||||
description: Run HTTP Action Group
|
||||
action: http_demo.action_group
|
||||
tags: [http, demo]
|
||||
confirm: true
|
||||
|
||||
- key: S
|
||||
description: Select a file
|
||||
|
38
examples/user_input_demo.py
Normal file
38
examples/user_input_demo.py
Normal file
@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
|
||||
from prompt_toolkit.validation import Validator
|
||||
|
||||
from falyx.action import Action, ChainedAction, UserInputAction
|
||||
|
||||
|
||||
def validate_alpha() -> Validator:
|
||||
def validate(text: str) -> bool:
|
||||
return text.isalpha()
|
||||
|
||||
return Validator.from_callable(
|
||||
validate,
|
||||
error_message="Please enter only alphabetic characters.",
|
||||
move_cursor_to_end=True,
|
||||
)
|
||||
|
||||
|
||||
chain = ChainedAction(
|
||||
name="Demo Chain",
|
||||
actions=[
|
||||
"Name",
|
||||
UserInputAction(
|
||||
name="User Input",
|
||||
prompt_text="Enter your {last_result}: ",
|
||||
validator=validate_alpha(),
|
||||
),
|
||||
Action(
|
||||
name="Display Name",
|
||||
action=lambda last_result: print(f"Hello, {last_result}!"),
|
||||
),
|
||||
],
|
||||
auto_inject=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(chain.preview())
|
||||
asyncio.run(chain())
|
Reference in New Issue
Block a user