feat: add erase_when_done parameter to prompt constructors#1
Open
tobiashochguertel wants to merge 1 commit intomainfrom
Open
feat: add erase_when_done parameter to prompt constructors#1tobiashochguertel wants to merge 1 commit intomainfrom
tobiashochguertel wants to merge 1 commit intomainfrom
Conversation
Expose prompt_toolkit's Application.erase_when_done as a first-class parameter on all prompts that create an Application instance directly (FuzzyPrompt, ListPrompt, NumberPrompt) and forward it through composite prompts that delegate to them (CheckboxPrompt, ExpandPrompt). When True, the rendered prompt UI is erased from the terminal when the application exits. This is useful when prompts are used in a loop (e.g. rebuilding a fuzzy picker after a state change) to avoid ghost/artifact lines accumulating in the terminal output. Without this parameter, users must reach into the private prompt._application.erase_when_done attribute after construction, which is fragile and undocumented. This change gives them a supported, documented path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reviewer's GuideAdds an erase_when_done parameter to several InquirerPy prompt constructors and threads it through to the underlying prompt_toolkit Application so prompts can cleanly clear their rendered output when they exit, especially in refresh-loop usage. Sequence diagram for prompt execution with erase_when_donesequenceDiagram
actor User
participant InquirerFacade as InquirerPy
participant FuzzyPrompt
participant Application
User->>InquirerFacade: fuzzy(message, choices, erase_when_done=True)
InquirerFacade->>FuzzyPrompt: __init__(message, choices, erase_when_done=True)
FuzzyPrompt->>FuzzyPrompt: set _erase_when_done = True
FuzzyPrompt->>Application: __init__(..., erase_when_done=_erase_when_done)
Note over Application: erase_when_done flag stored internally
User->>FuzzyPrompt: execute_async()
FuzzyPrompt->>Application: run_async()
Application-->>FuzzyPrompt: result
FuzzyPrompt-->>User: selected value
Application->>Application: exit
alt erase_when_done is True
Application->>Terminal: clear rendered prompt area
else erase_when_done is False
Application->>Terminal: leave rendered prompt on screen
end
Updated class diagram for prompt constructors with erase_when_doneclassDiagram
class Application {
+bool erase_when_done
+__init__(layout, style, key_bindings, after_render, editing_mode, erase_when_done)
}
class BaseListPrompt {
<<abstract>>
+message
+choices
+execute()
+execute_async()
}
class BaseComplexPrompt {
<<abstract>>
+message
+execute()
+execute_async()
}
class ListPrompt {
+bool _show_cursor
+bool _erase_when_done
+__init__(message, choices, style, default, height, max_height, keybindings, show_cursor, instruction, transformer, filter, validate, invalid_message, multiselect, keybind_help, show_cursor, vi_mode, mandatory, mandatory_message, session_result, erase_when_done)
}
class FuzzyPrompt {
+bool _erase_when_done
+__init__(message, choices, style, default, keybindings, vi_mode, instruction, long_instruction, separator, transformer, filter, validate, invalid_message, mandatory, mandatory_message, session_result, erase_when_done)
}
class CheckboxPrompt {
+__init__(message, choices, style, default, height, max_height, keybindings, instruction, transformer, filter, validate, invalid_message, keybind_help, show_cursor, vi_mode, mandatory, mandatory_message, session_result, erase_when_done)
}
class ExpandPrompt {
+__init__(message, choices, style, default, height, max_height, keybindings, instruction, expand_pointer, expand_selected, expand_help, help_msg, keybind_help, show_cursor, vi_mode, mandatory, mandatory_message, session_result, erase_when_done)
}
class NumberPrompt {
+bool _erase_when_done
+__init__(message, style, default, float_allowed, min_allowed, max_allowed, step, precision, keybindings, instruction, transformer, filter, validate, invalid_message, show_cursor, border, vi_mode, mandatory, mandatory_message, session_result, erase_when_done)
}
BaseListPrompt <|-- ListPrompt
BaseListPrompt <|-- FuzzyPrompt
ListPrompt <|-- CheckboxPrompt
ListPrompt <|-- ExpandPrompt
BaseComplexPrompt <|-- NumberPrompt
ListPrompt --> Application : creates
FuzzyPrompt --> Application : creates
CheckboxPrompt --> Application : creates via super
ExpandPrompt --> Application : creates via super
NumberPrompt --> Application : creates
ListPrompt ..> Application : pass erase_when_done
FuzzyPrompt ..> Application : pass erase_when_done
CheckboxPrompt ..> Application : pass erase_when_done
ExpandPrompt ..> Application : pass erase_when_done
NumberPrompt ..> Application : pass erase_when_done
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When using InquirerPy prompts inside a refresh loop (creating a new prompt instance each iteration, e.g. to rebuild a picker after a state change), the previous prompt leaves ghost/artifact lines on the terminal because
Applicationexits without clearing its rendered output.The underlying
prompt_toolkit.Applicationalready supports anerase_when_doneattribute that, whenTrue, wipes the rendered area on exit. However, InquirerPy does not expose this as a constructor parameter. Users are forced to reach into the privateprompt._application.erase_when_doneattribute after construction:Change
Add
erase_when_done: bool = Falseto the constructors of all prompts that create anApplicationdirectly, and thread it through composite prompts:prompts/fuzzy.pyFuzzyPromptself._erase_when_done, pass toApplication()prompts/list.pyListPromptprompts/number.pyNumberPromptprompts/checkbox.pyCheckboxPromptsuper().__init__()prompts/expand.pyExpandPromptsuper().__init__()Docstrings updated on all modified
__init__methods.Usage after this change
Testing
tests/prompts/test_number.pyare caused by aconftest.pyincompatibility with newer prompt_toolkit (create_pipe_input()returns a context manager; calling.close()on it fails). These failures exist on the unmodifiedmasterbranch and are unrelated to this PR.Upstream note
This PR is targeting the fork (
tobiashochguertel/InquirerPy). Once reviewed/merged here, a corresponding PR can be opened againstkazhala/InquirerPyupstream.Summary by Sourcery
Expose a new option on interactive prompts to clear their rendered output when the underlying application exits, improving terminal behavior in refresh-loop usage.
New Features:
Enhancements: