Skip to content
Prev Previous commit
Next Next commit
fixup CI failures; rprompt doesn't change in prompt, don't need Condi…
…tionalContainer
  • Loading branch information
Bob Hyman committed Oct 2, 2020
commit 1bf9ce19c77564da797515cb0a5bfaa4cbd13e5f
3 changes: 3 additions & 0 deletions prompt_toolkit/formatted_text/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def __pt_formatted_text__(self) -> StyleAndTextTuples:
def __repr__(self) -> str:
return "FormattedText(%s)" % super().__repr__()

def __len__(self) -> int:
return sum(len(t) for s, t in self)


class Template:
"""
Expand Down
13 changes: 8 additions & 5 deletions prompt_toolkit/layout/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def __init__(
self,
content: AnyContainer,
floats: List["Float"],
floats_min_preferred_height: Optional[Callable[[],int]] = None,
floats_min_preferred_height: Optional[Callable[[], int]] = None,
modal: bool = False,
key_bindings: Optional[KeyBindingsBase] = None,
style: Union[str, Callable[[], str]] = "",
Expand Down Expand Up @@ -806,10 +806,13 @@ def preferred_height(self, width: int, max_available_height: int) -> Dimension:
if self.floats_min_preferred_height:
floats_ph = min(
max(
[
f.content.preferred_height(width, max_available_height).preferred
for f in self.floats
]),
[
f.content.preferred_height(
width, max_available_height
).preferred
for f in self.floats
]
),
self.floats_min_preferred_height() or 0,
)
ph.preferred += floats_ph
Expand Down
4 changes: 1 addition & 3 deletions prompt_toolkit/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ def render(
:param is_done: When True, put the cursor at the end of the interface. We
won't print any changes to this part.
"""

output = self.output

# Enter alternate screen.
Expand Down Expand Up @@ -624,11 +623,10 @@ def render(
).preferred
else:
last_height = self._last_screen.height if self._last_screen else 0
preferred = layout.container.preferred_height(size.columns, size.rows).preferred
height = max(
self._min_available_height,
last_height,
preferred,
layout.container.preferred_height(size.columns, size.rows).preferred,
)

height = min(height, size.rows)
Expand Down
29 changes: 14 additions & 15 deletions prompt_toolkit/shortcuts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(
validator: Optional[Validator] = None,
completer: Optional[Completer] = None,
complete_in_thread: bool = False,
reserve_space_for_menu: int = None,
reserve_space_for_menu: int = 0,
complete_style: CompleteStyle = CompleteStyle.COLUMN,
auto_suggest: Optional[AutoSuggest] = None,
style: Optional[BaseStyle] = None,
Expand Down Expand Up @@ -609,16 +609,6 @@ def get_reserve_space_for_menu() -> int:
"""dynamic function to fetch current setting of the attribute."""
return self.reserve_space_for_menu

right_prompt = ConditionalContainer(
Window(
FormattedTextControl(text=lambda: self.rprompt),
align=WindowAlign.RIGHT,
style="class:rprompt",
),
filter=~is_done
& Condition(lambda: self.rprompt is not None and len(self.rprompt) > 0),
)

# Build the layout.
layout = HSplit(
[
Expand Down Expand Up @@ -682,7 +672,16 @@ def get_reserve_space_for_menu() -> int:
# line at the bottom of the screen if it is configured.
# To fix, would need to know height of left prompt.
Float(
content=right_prompt,
content=None
if (not self.rprompt)
or len(to_formatted_text(self.rprompt)) == 0
else (
Window(
FormattedTextControl(text=lambda: self.rprompt),
align=WindowAlign.RIGHT,
style="class:rprompt",
)
),
right=0,
# bottom=0, # right prompt floats to *top* of prompt.
hide_when_covering_content=True,
Expand Down Expand Up @@ -882,7 +881,7 @@ def prompt(
mouse_support: Optional[FilterOrBool] = None,
input_processors: Optional[List[Processor]] = None,
placeholder: Optional[AnyFormattedText] = None,
reserve_space_for_menu: Optional[int] = None,
reserve_space_for_menu: int = 0,
enable_system_prompt: Optional[FilterOrBool] = None,
enable_suspend: Optional[FilterOrBool] = None,
enable_open_in_editor: Optional[FilterOrBool] = None,
Expand Down Expand Up @@ -1101,7 +1100,7 @@ async def prompt_async(
mouse_support: Optional[FilterOrBool] = None,
input_processors: Optional[List[Processor]] = None,
placeholder: Optional[AnyFormattedText] = None,
reserve_space_for_menu: Optional[int] = None,
reserve_space_for_menu: int = 0,
enable_system_prompt: Optional[FilterOrBool] = None,
enable_suspend: Optional[FilterOrBool] = None,
enable_open_in_editor: Optional[FilterOrBool] = None,
Expand Down Expand Up @@ -1346,7 +1345,7 @@ def prompt(
mouse_support: Optional[FilterOrBool] = None,
input_processors: Optional[List[Processor]] = None,
placeholder: Optional[AnyFormattedText] = None,
reserve_space_for_menu: Optional[int] = None,
reserve_space_for_menu: int = 0,
enable_system_prompt: Optional[FilterOrBool] = None,
enable_suspend: Optional[FilterOrBool] = None,
enable_open_in_editor: Optional[FilterOrBool] = None,
Expand Down