Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `TabbedContent` widget https://github.com/Textualize/textual/pull/2059
- Added `get_child_by_type` method to widgets / app https://github.com/Textualize/textual/pull/2059
- Added `Widget.render_str` method https://github.com/Textualize/textual/pull/2059
- Added TEXTUAL_DRIVER environment variable


## [0.15.1] - 2023-03-14
Expand Down
20 changes: 19 additions & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import importlib
import inspect
import io
import os
Expand Down Expand Up @@ -47,7 +48,7 @@
from rich.segment import Segment, Segments
from rich.traceback import Traceback

from . import Logger, LogGroup, LogVerbosity, actions, events, log, messages
from . import Logger, LogGroup, LogVerbosity, actions, constants, events, log, messages
from ._animator import DEFAULT_EASING, Animatable, Animator, EasingFunction
from ._ansi_sequences import SYNC_END, SYNC_START
from ._asyncio import create_task
Expand Down Expand Up @@ -590,7 +591,24 @@ def get_driver_class(self) -> Type[Driver]:
Returns:
A Driver class which manages input and display.
"""

driver_class: Type[Driver]

driver_import = constants.DRIVER
if driver_import is not None:
# The driver class is set from the environment
# Syntax should be foo.bar.baz:MyDriver
module_import, colon, driver_symbol = driver_import.partition(":")
driver_module = importlib.import_module(module_import)
driver_class = getattr(driver_module, driver_symbol)
if not inspect.isclass(driver_class) or not issubclass(
driver_class, Driver
):
raise RuntimeError(
f"Unable to import {driver_import!r}; {driver_class!r} is not a Driver class "
)
return driver_class

if WINDOWS:
from .drivers.windows_driver import WindowsDriver

Expand Down
6 changes: 6 additions & 0 deletions src/textual/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"""

from __future__ import annotations

import os

from typing_extensions import Final
Expand All @@ -11,6 +13,8 @@

__all__ = ["BORDERS"]

get_environ = os.environ.get


def get_environ_bool(name: str) -> bool:
"""Check an environment variable switch.
Expand All @@ -28,3 +32,5 @@ def get_environ_bool(name: str) -> bool:
BORDERS = list(BORDER_CHARS)

DEBUG: Final[bool] = get_environ_bool("TEXTUAL_DEBUG")

DRIVER: Final[str | None] = get_environ("TEXTUAL_DRIVER", None)