Skip to content

Commit

Permalink
Merge pull request #1050 from doronz88/bugfix/remove-coloring-on-non-tty
Browse files Browse the repository at this point in the history
cli_common: remove coloring on non-tty outputs
  • Loading branch information
doronz88 committed Jun 5, 2024
2 parents 5725b1c + 76ed4fb commit 0b09e77
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pymobiledevice3/cli/cli_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import logging
import os
import sys
import uuid
from functools import wraps
from typing import Callable, List, Mapping, Optional, Tuple
Expand Down Expand Up @@ -76,7 +77,7 @@ def print_json(buf, colored: Optional[bool] = None, default=default_json_encoder
if colored is None:
colored = user_requested_colored_output()
formatted_json = json.dumps(buf, sort_keys=True, indent=4, default=default)
if colored:
if colored and os.isatty(sys.stdout.fileno()):
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
formatters.TerminalTrueColorFormatter(style='stata-dark'))
print(colorful_json)
Expand Down Expand Up @@ -104,7 +105,7 @@ def set_color_flag(ctx, param, value) -> None:


def user_requested_colored_output() -> bool:
return COLORED_OUTPUT
return COLORED_OUTPUT and os.isatty(sys.stdout.fileno())


def get_last_used_terminal_formatting(buf: str) -> str:
Expand Down

0 comments on commit 0b09e77

Please sign in to comment.