# Path: patchew/logviewer.py
# def ansi2html(input, white_bg=False):
#     c = ANSI2HTMLConverter(white_bg=white_bg)
#     yield from c.convert(input)
#     yield from c.finish()
# 
# def ansi2text(input):
#     c = ANSI2TextConverter()
#     yield from c.convert(input)
#     yield from c.finish()
# 
# class ANSI2TextConverter(ANSIProcessor):
#     FF = "\u2500" * 72 + "\n"
#     SYMBOLS = {
#         "\x00": "\u2400",
#         "\x01": "\u2401",
#         "\x02": "\u2402",
#         "\x03": "\u2403",
#         "\x04": "\u2404",
#         "\x05": "\u2405",
#         "\x06": "\u2406",
#         "\x07": "\U00001F514",
#         "\x0B": "\u240B",
#         "\x0E": "\u240E",
#         "\x0F": "\u240F",
#         "\x10": "\u2410",
#         "\x11": "\u2411",
#         "\x12": "\u2412",
#         "\x13": "\u2413",
#         "\x14": "\u2414",
#         "\x15": "\u2415",
#         "\x16": "\u2416",
#         "\x17": "\u2417",
#         "\x18": "\u2418",
#         "\x19": "\u2419",
#         "\x1A": "\u241A",
#         "\x1B": "\u241B",
#         "\x1C": "\u241C",
#         "\x1D": "\u241D",
#         "\x1E": "\u241E",
#         "\x1F": "\u241F",
#         "\x7F": "\u2326",
#     }
#     RE_SYMBOLS = re.compile("[\x00-\x1F\x7F]")
# 
#     def _write_span(self, text, class_id):
#         yield self.RE_SYMBOLS.sub(lambda x: self.SYMBOLS[x.group(0)], text)
# 
#     def _write_form_feed(self):
#         yield self.FF


import unittest
from patchew.logviewer import ansi2html, ansi2text, ANSI2TextConverter
        )

    # combining cursor movement and formatting
    def test_movement_and_formatting(self):
        self.assertBlackBg("\x1b[42m\tabc", '        <span class="BHIG">abc</span>')
        self.assertWhiteBg("\x1b[42m\tabc", '        <span class="BHIG">abc</span>')
        self.assertBlackBg("abc\x1b[42m\x1b[1Kabc", '   <span class="BHIG">abc</span>')
        self.assertWhiteBg("abc\x1b[42m\x1b[1Kabc", '   <span class="BHIG">abc</span>')
        self.assertBlackBg("\x1b[7m\tabc", '        <span class="BLK BWHI">abc</span>')
        self.assertWhiteBg("\x1b[7m\tabc", '        <span class="WHI BBLK">abc</span>')
        self.assertBlackBg(
            "abc\x1b[7m\x1b[1Kabc", '   <span class="BLK BWHI">abc</span>'
        )
        self.assertWhiteBg(
            "abc\x1b[7m\x1b[1Kabc", '   <span class="WHI BBLK">abc</span>'
        )


class ANSI2TextTest(unittest.TestCase):
    def assertAnsi(self, test, expected, **kwargs):
        self.assertEqual("".join(ansi2text(test, **kwargs)), expected, repr(test))

    # basic formatting tests
    def test_basic(self):
        self.assertAnsi("\tb", "        b")
        self.assertAnsi("\t\ta", "                a")
        self.assertAnsi("a\tb", "a       b")
        self.assertAnsi("ab\tc", "ab      c")
        self.assertAnsi("a\nbc", "a\nbc")
        self.assertAnsi("a\f", "a\n" + ANSI2TextConverter.FF)

# Path: patchew/logviewer.py
# def ansi2html(input, white_bg=False):
#     c = ANSI2HTMLConverter(white_bg=white_bg)
#     yield from c.convert(input)
#     yield from c.finish()
# 
# def ansi2text(input):
#     c = ANSI2TextConverter()
#     yield from c.convert(input)
#     yield from c.finish()
# 
# class ANSI2TextConverter(ANSIProcessor):
#     FF = "\u2500" * 72 + "\n"
#     SYMBOLS = {
#         "\x00": "\u2400",
#         "\x01": "\u2401",
#         "\x02": "\u2402",
#         "\x03": "\u2403",
#         "\x04": "\u2404",
#         "\x05": "\u2405",
#         "\x06": "\u2406",
#         "\x07": "\U00001F514",
#         "\x0B": "\u240B",
#         "\x0E": "\u240E",
#         "\x0F": "\u240F",
#         "\x10": "\u2410",
#         "\x11": "\u2411",
#         "\x12": "\u2412",
#         "\x13": "\u2413",
#         "\x14": "\u2414",
#         "\x15": "\u2415",
#         "\x16": "\u2416",
#         "\x17": "\u2417",
#         "\x18": "\u2418",
#         "\x19": "\u2419",
#         "\x1A": "\u241A",
#         "\x1B": "\u241B",
#         "\x1C": "\u241C",
#         "\x1D": "\u241D",
#         "\x1E": "\u241E",
#         "\x1F": "\u241F",
#         "\x7F": "\u2326",
#     }
#     RE_SYMBOLS = re.compile("[\x00-\x1F\x7F]")
# 
#     def _write_span(self, text, class_id):
#         yield self.RE_SYMBOLS.sub(lambda x: self.SYMBOLS[x.group(0)], text)
# 
#     def _write_form_feed(self):
#         yield self.FF


# Path: tests/test_ansi2html.py
import unittest
from patchew.logviewer import ansi2html, ansi2text, ANSI2TextConverter

        )

    # combining cursor movement and formatting
    def test_movement_and_formatting(self):
        self.assertBlackBg("\x1b[42m\tabc", '        <span class="BHIG">abc</span>')
        self.assertWhiteBg("\x1b[42m\tabc", '        <span class="BHIG">abc</span>')
        self.assertBlackBg("abc\x1b[42m\x1b[1Kabc", '   <span class="BHIG">abc</span>')
        self.assertWhiteBg("abc\x1b[42m\x1b[1Kabc", '   <span class="BHIG">abc</span>')
        self.assertBlackBg("\x1b[7m\tabc", '        <span class="BLK BWHI">abc</span>')
        self.assertWhiteBg("\x1b[7m\tabc", '        <span class="WHI BBLK">abc</span>')
        self.assertBlackBg(
            "abc\x1b[7m\x1b[1Kabc", '   <span class="BLK BWHI">abc</span>'
        )
        self.assertWhiteBg(
            "abc\x1b[7m\x1b[1Kabc", '   <span class="WHI BBLK">abc</span>'
        )


class ANSI2TextTest(unittest.TestCase):
    def assertAnsi(self, test, expected, **kwargs):
        self.assertEqual("".join(ansi2text(test, **kwargs)), expected, repr(test))

    # basic formatting tests
    def test_basic(self):
        self.assertAnsi("\tb", "        b")
        self.assertAnsi("\t\ta", "                a")
        self.assertAnsi("a\tb", "a       b")
        self.assertAnsi("ab\tc", "ab      c")
        self.assertAnsi("a\nbc", "a\nbc")
        self.assertAnsi("a\f", "a\n" + ANSI2TextConverter.FF)

        self.assertAnsi("a\n\f", "a\n\n" + ANSI2TextConverter.FF)