-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Module contains :class:`.InstructionWindow` which can be used to display long instructions.""" | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from prompt_toolkit.layout.containers import ConditionalContainer, Window | ||
from prompt_toolkit.layout.controls import FormattedTextControl | ||
|
||
if TYPE_CHECKING: | ||
from prompt_toolkit.filters.base import FilterOrBool | ||
from prompt_toolkit.formatted_text.base import AnyFormattedText | ||
|
||
|
||
class InstructionWindow(ConditionalContainer): | ||
"""Conditional `prompt_toolkit` :class:`~prompt_toolkit.layout.Window` that displays long instructions. | ||
Args: | ||
message: Long instructions to display. | ||
filter: Condition to display the instruction window. | ||
""" | ||
|
||
def __init__(self, message: str, filter: "FilterOrBool", wrap_lines: bool) -> None: | ||
self._message = message | ||
super().__init__( | ||
Window( | ||
FormattedTextControl(text=self._get_message), | ||
dont_extend_height=True, | ||
wrap_lines=wrap_lines, | ||
), | ||
filter=filter, | ||
) | ||
|
||
def _get_message(self) -> "AnyFormattedText": | ||
"""Get long instruction to display. | ||
Returns: | ||
FormattedText in list of tuple format. | ||
""" | ||
return [("class:instruction", self._message)] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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