diff --git a/graphtage/__main__.py b/graphtage/__main__.py index 5a2ad9a..469b5f3 100644 --- a/graphtage/__main__.py +++ b/graphtage/__main__.py @@ -113,6 +113,8 @@ def main(argv=None) -> int: help='do not print a newline after each key/value pair in a dictionary') formatting.add_argument('--condensed', '-j', action='store_true', help='equivalent to `-jl -jd`') formatting.add_argument('--html', action='store_true', help='output the diff in HTML') + formatting.add_argument('--no-unicode', action='store_true', + help='do not use Unicode combining marks in the output (only use colors)') key_match_strategy = parser.add_mutually_exclusive_group() key_match_strategy.add_argument("--dict-strategy", "-ds", choices=("auto", "match", "none"), help="sets the strategy for matching dictionary key/value pairs: `auto` (the " @@ -206,7 +208,8 @@ def printer_type(*pos_args, **kwargs): options={ 'join_lists': args.condensed or args.join_lists, 'join_dict_items': args.condensed or args.join_dict_items - } + }, + enable_unicode=not args.no_unicode ) printermodule.DEFAULT_PRINTER = printer diff --git a/graphtage/printer.py b/graphtage/printer.py index 701a880..3ac97f0 100644 --- a/graphtage/printer.py +++ b/graphtage/printer.py @@ -450,7 +450,8 @@ def __init__( out_stream: Optional[Writer] = None, ansi_color: Optional[bool] = None, quiet: bool = False, - options: Optional[Dict[str, Any]] = None + options: Optional[Dict[str, Any]] = None, + enable_unicode: bool = True ): """Initializes a Printer. @@ -461,6 +462,8 @@ def __init__( quiet: If :const:`True`, progress and status messages will be suppressed. options: An optional dict, the keys of which will be set as attributes of this class. This is used to provide additional formatting options to functions that use this printer. + enable_unicode: Whether or not Unicode combining marks should be used in the output. If :const:`False`, + only ANSI colors will be used to highlight differences. """ if out_stream is None: @@ -472,6 +475,7 @@ def __init__( self._context_type: Type[ANSIContext] = ANSIContext self.out_stream: CombiningMarkWriter = CombiningMarkWriter(self) """The stream wrapped by this printer.""" + self.out_stream.enabled = enable_unicode self.indents: int = 0 """The number of indent steps.""" self.indent_str: str = ' ' * 4