diff --git a/jut/__init__.py b/jut/__init__.py index 9609785..33904d3 100644 --- a/jut/__init__.py +++ b/jut/__init__.py @@ -69,6 +69,7 @@ class Config(BaseModel): tail: int single_page: bool full_display: bool + force_colors: bool @validator("input_file") def validate_input_file(cls, val): @@ -147,7 +148,7 @@ def __init__(self, config: Config): custom_theme = Theme( {"info": "dim cyan", "warning": "magenta", "danger": "bold red"} ) - self.console = Console(theme=custom_theme) + self.console = Console(theme=custom_theme, force_terminal=config.force_colors) def parse_notebook(self): """Parse the notebook content.""" diff --git a/jut/cli.py b/jut/cli.py index 6742437..43463e0 100644 --- a/jut/cli.py +++ b/jut/cli.py @@ -52,7 +52,14 @@ def download_url(url): is_flag=True, help="Should all the contents in the file displayed?", ) -def display(url, input_file, head, tail, single_page, full_display): +@click.option( + "--force-colors", + type=bool, + default=False, + is_flag=True, + help="Force colored output even if stdout is not a terminal", +) +def display(url, input_file, head, tail, single_page, full_display, force_colors): destination_file = None if url: destination_file = download_url(url) @@ -77,6 +84,7 @@ def display(url, input_file, head, tail, single_page, full_display): tail=tail, single_page=single_page, full_display=full_display, + force_colors=force_colors, ) render = Render(config) render.render()