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

Add a minimum value for TEXTUAL_FPS (_get_environ_int was extended with new functionality) and set the FPS to 60 if you set the environment value to 0. #5176

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 18 additions & 3 deletions src/textual/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,29 @@ def _get_environ_bool(name: str) -> bool:
return has_environ


def _get_environ_int(name: str, default: int) -> int:
def _get_environ_int(name: str, default: int, *, min_value: Optional[int] = None, max_value: Optional[int] = None) -> int:
"""Retrieves an integer environment variable.

Args:
name: Name of environment variable.
default: The value to use if the value is not set, or set to something other
than a valid integer.

Keyword args:
min_value (optional): The minimum value that should be returned by this function.
max_value (optional): The maximum value that should be returned by this function.

Returns:
The integer associated with the environment variable if it's set to a valid int
or the default value otherwise.
"""
try:
return int(os.environ[name])
value = int(os.environ[name])
if min_value is not None and value < min_value:
return min_value
if max_value is not None and value > max_value:
return max_value
return value
except KeyError:
return default
except ValueError:
Expand Down Expand Up @@ -107,9 +116,15 @@ def _get_textual_animations() -> AnimationLevel:
SHOW_RETURN: Final[bool] = _get_environ_bool("TEXTUAL_SHOW_RETURN")
"""Write the return value on exit."""

MAX_FPS: Final[int] = _get_environ_int("TEXTUAL_FPS", 60)
MAX_FPS_DEFAULT: Final[int] = 60
"""The default value for MAX_FPS."""

MAX_FPS: Final[int] = _get_environ_int("TEXTUAL_FPS", MAX_FPS_DEFAULT, min_value=0)
"""Maximum frames per second for updates."""

if MAX_FPS == 0:
MAX_FPS = MAX_FPS_DEFAULT

COLOR_SYSTEM: Final[str | None] = get_environ("TEXTUAL_COLOR_SYSTEM", "auto")
"""Force color system override."""

Expand Down