-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dedicated instruction area (tips). #7
- Loading branch information
Showing
9 changed files
with
85 additions
and
3 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,36 @@ | ||
"""Module contains :class:`.TipsWindow` which can be used to display additional tips/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 TipsWindow(ConditionalContainer): | ||
"""Conditional `prompt_toolkit` :class:`~prompt_toolkit.layout.Window` that displays tips/instructions. | ||
Args: | ||
message: Tips to display. | ||
filter: Condition to display the tips window. | ||
""" | ||
|
||
def __init__(self, message: str, filter: "FilterOrBool") -> None: | ||
self._message = message | ||
super().__init__( | ||
Window( | ||
FormattedTextControl(text=self._get_message), dont_extend_height=True | ||
), | ||
filter=filter, | ||
) | ||
|
||
def _get_message(self) -> "AnyFormattedText": | ||
"""Get tips 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
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