# Path: diffoscope/presenters/text.py
# class TextPresenter(Presenter):
#     PREFIX = u'│ '
#     RE_PREFIX = re.compile(r'(^|\n)')
# 
#     def __init__(self, print_func, color):
#         self.print_func = create_limited_print_func(
#             print_func,
#             Config().max_text_report_size,
#         )
#         self.color = color
# 
#         super().__init__()
# 
#     def start(self, difference):
#         try:
#             super().start(difference)
#         except PrintLimitReached:
#             self.print_func("Max output size reached.", force=True)
# 
#     def visit_difference(self, difference):
#         if self.depth == 0:
#             self.output("--- {}".format(difference.source1))
#             self.output("+++ {}".format(difference.source2))
#         elif difference.source1 == difference.source2:
#             self.output(u"├── {}".format(difference.source1))
#         else:
#             self.output(u"│   --- {}".format(difference.source1))
#             self.output(u"├── +++ {}".format(difference.source2))
# 
#         for x in difference.comments:
#             self.output(u"│┄ {}".format(x))
# 
#         diff = difference.unified_diff
# 
#         if diff:
#             self.output(color_unified_diff(diff) if self.color else diff, True)
# 
#     def output(self, val, raw=False):
#         self.print_func(
#             self.indent(val, self.PREFIX * (self.depth + 0 if raw else -1)),
#         )
# 
# Path: diffoscope/presenters/json.py
# class JSONPresenter(Presenter):
#     def __init__(self, print_func):
#         self.root = []
#         self.current = self.root
#         self.print_func = print_func
# 
#         super().__init__()
# 
#     def start(self, difference):
#         super().start(difference)
# 
#         self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
# 
#     def visit_difference(self, difference):
#         self.current.append({
#             'source1': difference.source1,
#             'source2': difference.source2,
#             'comments': [x for x in difference.comments],
#             'differences': [],
#             'unified_diff': difference.unified_diff,
#         })
# 
#         self.current = self.current[-1]['differences']
# 
# Path: diffoscope/presenters/utils.py
# @contextlib.contextmanager
# def make_printer(path):
#     output = sys.stdout
# 
#     if path != '-':
#         output = codecs.open(path, 'w', encoding='utf-8')
# 
#     def fn(*args, **kwargs):
#         kwargs['file'] = output
#         print(*args, **kwargs)
#     fn.output = output
# 
#     yield fn
# 
#     if path != '-':
#         output.close()
# 
# Path: diffoscope/presenters/markdown.py
# class MarkdownTextPresenter(Presenter):
#     def __init__(self, print_func):
#         self.print_func = print_func
#         super().__init__()
# 
#     def visit_difference(self, difference):
#         if difference.source1 == difference.source2:
#             self.title(difference.source1)
#         else:
#             self.title("Comparing {} & {}".format(
#                 difference.source1,
#                 difference.source2,
#             ))
# 
#         for x in difference.comments:
#             self.print_func(x)
#             self.print_func()
# 
#         if difference.unified_diff:
#             self.print_func(self.indent(difference.unified_diff, '    '))
#             self.print_func()
# 
#     def title(self, val):
#         prefix = '#' * min(self.depth + 1, 6)
# 
#         self.print_func("{} {}".format(prefix, val))
#         self.print_func()
# 
# Path: diffoscope/presenters/restructuredtext.py
# class RestructuredTextPresenter(Presenter):
#     TITLE_CHARS = '=-`:.\'"~^_*+#'
# 
#     def __init__(self, print_func):
#         self.print_func = print_func
#         super().__init__()
# 
#     def visit_difference(self, difference):
#         if difference.source1 == difference.source2:
#             self.title(difference.source1)
#         else:
#             self.title("Comparing {} & {}".format(
#                 difference.source1,
#                 difference.source2,
#             ))
# 
#         for x in difference.comments:
#             self.print_func()
#             self.print_func(x)
# 
#         if difference.unified_diff:
#             self.print_func('::')
#             self.print_func()
#             self.print_func(self.indent(difference.unified_diff, '    '))
#             self.print_func()
# 
#     def title(self, val):
#         char = self.TITLE_CHARS[self.depth % len(self.TITLE_CHARS)]
# 
#         if self.depth < len(self.TITLE_CHARS):
#             self.print_func(len(val) * char)
# 
#         self.print_func(val)
#         self.print_func(len(val) * char)
#         self.print_func()


import sys
import logging
from ..profiling import profile
from .text import TextPresenter
from .json import JSONPresenter
from .html import output_html, output_html_directory
from .utils import make_printer
from .markdown import MarkdownTextPresenter
from .restructuredtext import RestructuredTextPresenter

logger = logging.getLogger(__name__)


def output_all(difference, parsed_args, has_differences):
    """
    Generate all known output formats.
    """

    if difference is None:
        return

    FORMATS = {
        'text': {
            'fn': text,
            'target': parsed_args.text_output,
        },
        'html': {
            'fn': html,
            'target': parsed_args.html_output,
        },
        'json': {
            'klass': JSONPresenter,
            'target': parsed_args.json_output,
        },
        'markdown': {
            'klass': MarkdownTextPresenter,
            'target': parsed_args.markdown_output,
        },
        'restructuredtext': {

# Path: diffoscope/presenters/text.py
# class TextPresenter(Presenter):
#     PREFIX = u'│ '
#     RE_PREFIX = re.compile(r'(^|\n)')
# 
#     def __init__(self, print_func, color):
#         self.print_func = create_limited_print_func(
#             print_func,
#             Config().max_text_report_size,
#         )
#         self.color = color
# 
#         super().__init__()
# 
#     def start(self, difference):
#         try:
#             super().start(difference)
#         except PrintLimitReached:
#             self.print_func("Max output size reached.", force=True)
# 
#     def visit_difference(self, difference):
#         if self.depth == 0:
#             self.output("--- {}".format(difference.source1))
#             self.output("+++ {}".format(difference.source2))
#         elif difference.source1 == difference.source2:
#             self.output(u"├── {}".format(difference.source1))
#         else:
#             self.output(u"│   --- {}".format(difference.source1))
#             self.output(u"├── +++ {}".format(difference.source2))
# 
#         for x in difference.comments:
#             self.output(u"│┄ {}".format(x))
# 
#         diff = difference.unified_diff
# 
#         if diff:
#             self.output(color_unified_diff(diff) if self.color else diff, True)
# 
#     def output(self, val, raw=False):
#         self.print_func(
#             self.indent(val, self.PREFIX * (self.depth + 0 if raw else -1)),
#         )
# 
# Path: diffoscope/presenters/json.py
# class JSONPresenter(Presenter):
#     def __init__(self, print_func):
#         self.root = []
#         self.current = self.root
#         self.print_func = print_func
# 
#         super().__init__()
# 
#     def start(self, difference):
#         super().start(difference)
# 
#         self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
# 
#     def visit_difference(self, difference):
#         self.current.append({
#             'source1': difference.source1,
#             'source2': difference.source2,
#             'comments': [x for x in difference.comments],
#             'differences': [],
#             'unified_diff': difference.unified_diff,
#         })
# 
#         self.current = self.current[-1]['differences']
# 
# Path: diffoscope/presenters/utils.py
# @contextlib.contextmanager
# def make_printer(path):
#     output = sys.stdout
# 
#     if path != '-':
#         output = codecs.open(path, 'w', encoding='utf-8')
# 
#     def fn(*args, **kwargs):
#         kwargs['file'] = output
#         print(*args, **kwargs)
#     fn.output = output
# 
#     yield fn
# 
#     if path != '-':
#         output.close()
# 
# Path: diffoscope/presenters/markdown.py
# class MarkdownTextPresenter(Presenter):
#     def __init__(self, print_func):
#         self.print_func = print_func
#         super().__init__()
# 
#     def visit_difference(self, difference):
#         if difference.source1 == difference.source2:
#             self.title(difference.source1)
#         else:
#             self.title("Comparing {} & {}".format(
#                 difference.source1,
#                 difference.source2,
#             ))
# 
#         for x in difference.comments:
#             self.print_func(x)
#             self.print_func()
# 
#         if difference.unified_diff:
#             self.print_func(self.indent(difference.unified_diff, '    '))
#             self.print_func()
# 
#     def title(self, val):
#         prefix = '#' * min(self.depth + 1, 6)
# 
#         self.print_func("{} {}".format(prefix, val))
#         self.print_func()
# 
# Path: diffoscope/presenters/restructuredtext.py
# class RestructuredTextPresenter(Presenter):
#     TITLE_CHARS = '=-`:.\'"~^_*+#'
# 
#     def __init__(self, print_func):
#         self.print_func = print_func
#         super().__init__()
# 
#     def visit_difference(self, difference):
#         if difference.source1 == difference.source2:
#             self.title(difference.source1)
#         else:
#             self.title("Comparing {} & {}".format(
#                 difference.source1,
#                 difference.source2,
#             ))
# 
#         for x in difference.comments:
#             self.print_func()
#             self.print_func(x)
# 
#         if difference.unified_diff:
#             self.print_func('::')
#             self.print_func()
#             self.print_func(self.indent(difference.unified_diff, '    '))
#             self.print_func()
# 
#     def title(self, val):
#         char = self.TITLE_CHARS[self.depth % len(self.TITLE_CHARS)]
# 
#         if self.depth < len(self.TITLE_CHARS):
#             self.print_func(len(val) * char)
# 
#         self.print_func(val)
#         self.print_func(len(val) * char)
#         self.print_func()


# Path: diffoscope/presenters/formats.py
import sys
import logging
from ..profiling import profile
from .text import TextPresenter
from .json import JSONPresenter
from .html import output_html, output_html_directory
from .utils import make_printer
from .markdown import MarkdownTextPresenter
from .restructuredtext import RestructuredTextPresenter


logger = logging.getLogger(__name__)


def output_all(difference, parsed_args, has_differences):
    """
    Generate all known output formats.
    """

    if difference is None:
        return

    FORMATS = {
        'text': {
            'fn': text,
            'target': parsed_args.text_output,
        },
        'html': {
            'fn': html,
            'target': parsed_args.html_output,
        },
        'json': {
            'klass': JSONPresenter,
            'target': parsed_args.json_output,
        },
        'markdown': {
            'klass': MarkdownTextPresenter,
            'target': parsed_args.markdown_output,
        },
        'restructuredtext': {

            'klass': RestructuredTextPresenter,