mirror of https://github.com/Textualize/rich.git
time card render
This commit is contained in:
parent
d65be46dc4
commit
d678050802
|
@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- Added force_terminal option to Console.**init**
|
||||
|
||||
## [0.8.8] - 2020-03-31
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import io
|
||||
from time import time
|
||||
|
||||
from rich.console import Console, ConsoleOptions, RenderGroup, RenderResult
|
||||
from rich.markdown import Markdown
|
||||
from rich.measure import Measurement
|
||||
|
@ -27,6 +30,7 @@ class ColorBox:
|
|||
|
||||
|
||||
def make_test_card() -> Table:
|
||||
"""Get a renderable that demonstrates a number of features."""
|
||||
table = Table.grid()
|
||||
table.title = "Rich features"
|
||||
table.expand = False
|
||||
|
@ -162,7 +166,11 @@ Supports much of the *markdown*, __syntax__!
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
console = Console()
|
||||
console = Console(file=io.StringIO(), force_terminal=True)
|
||||
test_card = make_test_card()
|
||||
start = time()
|
||||
console.print(test_card)
|
||||
console.print()
|
||||
taken = int((time() - start) * 1000.0)
|
||||
print(console.file.getvalue())
|
||||
print()
|
||||
print(f"rendered in {taken}ms")
|
||||
|
|
|
@ -243,6 +243,7 @@ class Console:
|
|||
color_system: Optional[
|
||||
Literal["auto", "standard", "256", "truecolor", "windows"]
|
||||
] = "auto",
|
||||
force_terminal: bool = False,
|
||||
theme: Theme = None,
|
||||
file: IO = None,
|
||||
width: int = None,
|
||||
|
@ -271,6 +272,7 @@ class Console:
|
|||
self.legacy_windows: bool = "WINDIR" in os.environ and not "WT_SESSION" in os.environ
|
||||
|
||||
self._color_system: Optional[ColorSystem]
|
||||
self._force_terminal = force_terminal
|
||||
if self.legacy_windows:
|
||||
_enable_legacy_windows_support()
|
||||
self.file = file or sys.stdout
|
||||
|
@ -384,6 +386,8 @@ class Console:
|
|||
bool: True if the console writting to a device capable of
|
||||
understanding terminal codes, otherwise False.
|
||||
"""
|
||||
if self._force_terminal:
|
||||
return True
|
||||
isatty = getattr(self.file, "isatty", None)
|
||||
return False if isatty is None else isatty()
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def install(
|
|||
|
||||
|
||||
Args:
|
||||
console (Optiona[Console], optional): Console to write exception to. Default uses internal Console instance.
|
||||
console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance.
|
||||
width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100.
|
||||
line_numbers (bool, optional): Enable line numbers.
|
||||
extra_lines (int, optional): Extra lines of code. Defaults to 3.
|
||||
|
|
Loading…
Reference in New Issue