Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persistent elements #103

Merged
merged 2 commits into from
Aug 5, 2024
Merged
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
7 changes: 6 additions & 1 deletion beaupy/_beaupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ class Config:
raise_on_escape(bool): If True, functions will raise Abort whenever the escape key is encountered when waiting for input, otherwise,
they will return some sane alternative to their usual return. For `select`, `prompt` and `confirm` this means `None`, while for
`select_multiple` it means an empty list - `[]`. Defaults to False.
transient(bool): If False, elements will remain displayed after its context has ended. Defaults to True.
"""

raise_on_interrupt: bool = False
raise_on_escape: bool = False
transient: bool = False


_navigation_keys = [DefaultKeys.up, DefaultKeys.down, DefaultKeys.right, DefaultKeys.left, DefaultKeys.home, DefaultKeys.end]
Expand Down Expand Up @@ -212,6 +214,7 @@ def prompt(
cursor_position=len(initial_value or ''),
),
renderer=renderer,
transient=Config.transient
)

with element.displayed():
Expand Down Expand Up @@ -304,6 +307,7 @@ def select(
page_size=page_size,
),
renderer=renderer,
transient=Config.transient
)

with element.displayed():
Expand Down Expand Up @@ -397,6 +401,7 @@ def select_multiple(
page_size=page_size,
),
renderer=renderer,
transient=Config.transient
)

with element.displayed():
Expand Down Expand Up @@ -445,7 +450,7 @@ def confirm(
Optional[bool]
"""
rendered = ''
with _cursor_hidden(console), Live(rendered, console=console, auto_refresh=False, transient=True) as live:
with _cursor_hidden(console), Live(rendered, console=console, auto_refresh=False, transient=Config.transient) as live:
if cursor_style in ['', None]:
warnings.warn('`cursor_style` should be a valid style, defaulting to `white`')
cursor_style = 'white'
Expand Down
26 changes: 13 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'beaupy'
version = '3.8.3.post1'
version = '3.9.0'
description = 'A library of elements for interactive TUIs in Python'
authors = ['Peter Vyboch <pvyboch1@gmail.com>']
license = 'MIT'
Expand Down Expand Up @@ -40,7 +40,7 @@ python = ">=3.7.8,<4.0.0"
rich = ">=12.2.0"
emoji = "^2.0.0"
python-yakh = "0.3.2"
questo = "^0.2.3"
questo = "^0.3.0"

[tool.mypy]
files = ["src"]
Expand Down
Loading