From d09aa7b72d776e69aff6355a1f8cd375c2d5cb94 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 29 Dec 2019 16:59:45 +0000 Subject: [PATCH] add file and flish to rich print --- rich/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rich/__init__.py b/rich/__init__.py index 6f1ae14d..0f7fbdc4 100644 --- a/rich/__init__.py +++ b/rich/__init__.py @@ -1,4 +1,4 @@ -from typing import Any, Optional, TYPE_CHECKING +from typing import Any, IO, Optional, TYPE_CHECKING if TYPE_CHECKING: from .console import Console @@ -7,16 +7,25 @@ if TYPE_CHECKING: _console: Optional["Console"] = None -def print(*objects: Any, sep=" ", end="\n", log_locals: bool = False): +def print( + *objects: Any, + sep=" ", + end="\n", + file: IO[str] = None, + flush: bool = False, + log_locals: bool = False +): global _console if _console is None: from .console import Console _console = Console() - return _console.log( + + write_console = _console if file is None else Console(file=file) + return write_console.log( *objects, sep=sep, end=end, log_locals=log_locals, _stack_offset=2 ) -if __name__ == "__main__": +if __name__ == "__main__": # pragma: no cover print("Hello, **World**", log_locals=True)