Skip to content

add default value option for input dialog #1616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2022
Merged

add default value option for input dialog #1616

merged 2 commits into from
Apr 20, 2022

Conversation

motty-mio2
Copy link
Contributor

Hello
I like this library so much and use it for me personal projects thanks. This PR is similar to previous (#1563).

What

I add an option to set default value for input dialog

Usage

from prompt_toolkit.shortcuts import input_dialog


def main():
    result = input_dialog(
                title="Input dialog example", 
                text="Please type your name:", 
                default_text="George"
            ).run()

    print(f"Result = {result}")


if __name__ == "__main__":
    main()

How it works

  • without edit
    default_value

  • editing
    edit

Related

@@ -109,6 +109,7 @@ def input_dialog(
validator: Optional[Validator] = None,
password: FilterOrBool = False,
style: Optional[BaseStyle] = None,
default_text: str = "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the parameter to default here?
For consistency with PromptSession: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py#L899

I know for the radiolist_dialog, it's default_values, but I think there it can be more than one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@jonathanslenders jonathanslenders merged commit 8ce4065 into prompt-toolkit:master Apr 20, 2022
@jonathanslenders
Copy link
Member

Thanks!

@motty-mio2 motty-mio2 deleted the input_default_text branch April 20, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants