Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion questionary/prompts/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def checkbox(
use_search_filter: Union[str, bool, None] = False,
instruction: Optional[str] = None,
show_description: bool = True,
keep_options_displayed: bool = True,
Copy link
Owner

Choose a reason for hiding this comment

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

please add a description for the parameter

**kwargs: Any,
) -> Question:
"""Ask the user to select from a list of items.
Expand Down Expand Up @@ -222,7 +223,9 @@ def perform_validation(selected_values: List[str]) -> bool:

return valid

layout = common.create_inquirer_layout(ic, get_prompt_tokens, **kwargs)
layout = common.create_inquirer_layout(
ic, get_prompt_tokens, keep_options_displayed=keep_options_displayed, **kwargs
)

bindings = KeyBindings()

Expand Down
6 changes: 5 additions & 1 deletion questionary/prompts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ def _fix_unecessary_blank_lines(ps: PromptSession) -> None:
def create_inquirer_layout(
ic: InquirerControl,
get_prompt_tokens: Callable[[], List[Tuple[str, str]]],
keep_options_displayed: bool = True, # New flag
**kwargs: Any,
) -> Layout:
"""Create a layout combining question and inquirer selection."""
Expand All @@ -618,11 +619,14 @@ def has_search_string():
bottom_toolbar=lambda: ic.error_message, **kwargs
)

# Modify the filter for options based on `keep_options_displayed`
options_filter = ~IsDone() if not keep_options_displayed else Always()

return Layout(
HSplit(
[
ps.layout.container,
ConditionalContainer(Window(ic), filter=~IsDone()),
ConditionalContainer(Window(ic), filter=options_filter), # Change here
ConditionalContainer(
Window(
height=LayoutDimension.exact(2),
Expand Down
4 changes: 3 additions & 1 deletion questionary/prompts/rawselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def rawselect(
qmark: str = DEFAULT_QUESTION_PREFIX,
pointer: Optional[str] = DEFAULT_SELECTED_POINTER,
style: Optional[Style] = None,
keep_options_displayed: bool = True,
Copy link
Owner

Choose a reason for hiding this comment

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

please add a description for the parameter

**kwargs: Any,
) -> Question:
"""Ask the user to select one item from a list of choices using shortcuts.
Expand Down Expand Up @@ -74,6 +75,7 @@ def rawselect(
pointer,
style,
use_shortcuts=True,
use_arrow_keys=False,
use_arrow_keys=True,
keep_options_displayed=keep_options_displayed,
**kwargs,
)
5 changes: 4 additions & 1 deletion questionary/prompts/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def select(
show_selected: bool = False,
show_description: bool = True,
instruction: Optional[str] = None,
keep_options_displayed: bool = True,
**kwargs: Any,
) -> Question:
"""A list of items to select **one** option from.
Expand Down Expand Up @@ -202,7 +203,9 @@ def get_prompt_tokens():

return tokens

layout = common.create_inquirer_layout(ic, get_prompt_tokens, **kwargs)
layout = common.create_inquirer_layout(
ic, get_prompt_tokens, keep_options_displayed=keep_options_displayed, **kwargs
)

bindings = KeyBindings()

Expand Down
26 changes: 16 additions & 10 deletions questionary/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def __init__(self, application: "Application[Any]") -> None:
self.default = None

async def ask_async(
self, patch_stdout: bool = False, kbi_msg: str = DEFAULT_KBI_MESSAGE
self,
patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE,
**kwargs: Any,
) -> Any:
"""Ask the question using asyncio and return user response.

Expand All @@ -40,13 +43,16 @@ async def ask_async(

try:
sys.stdout.flush()
return await self.unsafe_ask_async(patch_stdout)
return await self.unsafe_ask_async(patch_stdout, **kwargs)
except KeyboardInterrupt:
print("{}".format(kbi_msg))
return None

def ask(
self, patch_stdout: bool = False, kbi_msg: str = DEFAULT_KBI_MESSAGE
self,
patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE,
**kwargs: Any,
) -> Any:
"""Ask the question synchronously and return user response.

Expand All @@ -61,12 +67,12 @@ def ask(
"""

try:
return self.unsafe_ask(patch_stdout)
return self.unsafe_ask(patch_stdout, **kwargs)
except KeyboardInterrupt:
print("{}".format(kbi_msg))
return None

def unsafe_ask(self, patch_stdout: bool = False) -> Any:
def unsafe_ask(self, patch_stdout: bool = False, **kwargs: Any) -> Any:
"""Ask the question synchronously and return user response.

Does not catch keyboard interrupts.
Expand All @@ -84,9 +90,9 @@ def unsafe_ask(self, patch_stdout: bool = False) -> Any:

if patch_stdout:
with prompt_toolkit.patch_stdout.patch_stdout():
return self.application.run()
return self.application.run(**kwargs)
else:
return self.application.run()
return self.application.run(**kwargs)

def skip_if(self, condition: bool, default: Any = None) -> "Question":
"""Skip the question if flag is set and return the default instead.
Expand All @@ -103,7 +109,7 @@ def skip_if(self, condition: bool, default: Any = None) -> "Question":
self.default = default
return self

async def unsafe_ask_async(self, patch_stdout: bool = False) -> Any:
async def unsafe_ask_async(self, patch_stdout: bool = False, **kwargs: Any) -> Any:
"""Ask the question using asyncio and return user response.

Does not catch keyboard interrupts.
Expand All @@ -124,9 +130,9 @@ async def unsafe_ask_async(self, patch_stdout: bool = False) -> Any:

if patch_stdout:
with prompt_toolkit.patch_stdout.patch_stdout():
r = self.application.run_async()
r = self.application.run_async(**kwargs)
else:
r = self.application.run_async()
r = self.application.run_async(**kwargs)

if utils.is_prompt_toolkit_3():
return await r
Expand Down