Skip to content

Commit

Permalink
feat: persistent elements (#103)
Browse files Browse the repository at this point in the history
* feat: persistent elements

* chore: updating dependencies
  • Loading branch information
petereon authored Aug 5, 2024
1 parent ba6673d commit 5b60fa8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
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

0 comments on commit 5b60fa8

Please sign in to comment.