# 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
        self.assertWhiteBg("\x1b[97;1mABC", '<span class="HIW BOLD">ABC</span>')
        self.assertBlackBg("\x1b[97;2mABC", "ABC")
        self.assertWhiteBg("\x1b[97;2mABC", '<span class="WHI">ABC</span>')
        self.assertBlackBg("\x1b[97;2;1mABC", '<span class="BOLD">ABC</span>')
        self.assertWhiteBg("\x1b[97;2;1mABC", '<span class="WHI BOLD">ABC</span>')
        self.assertBlackBg("\x1b[100mABC", '<span class="BHIK">ABC</span>')
        self.assertWhiteBg("\x1b[100mABC", '<span class="BHIK">ABC</span>')
        self.assertBlackBg("\x1b[38;5;120mABC", '<span class="f120">ABC</span>')
        self.assertWhiteBg("\x1b[38;5;120mABC", '<span class="f120">ABC</span>')
        self.assertBlackBg("\x1b[38;5;120;2mABC", '<span class="df120">ABC</span>')
        self.assertWhiteBg("\x1b[38;5;120;2mABC", '<span class="df120">ABC</span>')
        self.assertBlackBg("\x1b[48;5;120mABC", '<span class="b120">ABC</span>')
        self.assertWhiteBg("\x1b[48;5;120mABC", '<span class="b120">ABC</span>')
        self.assertBlackBg("\x1b[48;5;120;2mABC", '<span class="HIK b120">ABC</span>')
        self.assertWhiteBg("\x1b[48;5;120;2mABC", '<span class="HIK b120">ABC</span>')

    # italic, underline, strikethrough
    def test_text_variants(self):
        self.assertBlackBg("\x1b[3mABC", '<span class="ITA">ABC</span>')
        self.assertWhiteBg("\x1b[3mABC", '<span class="ITA">ABC</span>')
        self.assertBlackBg("\x1b[3;31mABC", '<span class="HIR ITA">ABC</span>')
        self.assertWhiteBg("\x1b[3;31mABC", '<span class="HIR ITA">ABC</span>')
        self.assertBlackBg("\x1b[3mAB\x1b[23mC", '<span class="ITA">AB</span>C')
        self.assertWhiteBg("\x1b[3mAB\x1b[23mC", '<span class="ITA">AB</span>C')
        self.assertBlackBg(
            "\x1b[3;31mAB\x1b[23mC",
            '<span class="HIR ITA">AB</span><span class="HIR">C</span>',
        )
        self.assertWhiteBg(
            "\x1b[3;31mAB\x1b[23mC",

# 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

        self.assertWhiteBg("\x1b[97;1mABC", '<span class="HIW BOLD">ABC</span>')
        self.assertBlackBg("\x1b[97;2mABC", "ABC")
        self.assertWhiteBg("\x1b[97;2mABC", '<span class="WHI">ABC</span>')
        self.assertBlackBg("\x1b[97;2;1mABC", '<span class="BOLD">ABC</span>')
        self.assertWhiteBg("\x1b[97;2;1mABC", '<span class="WHI BOLD">ABC</span>')
        self.assertBlackBg("\x1b[100mABC", '<span class="BHIK">ABC</span>')
        self.assertWhiteBg("\x1b[100mABC", '<span class="BHIK">ABC</span>')
        self.assertBlackBg("\x1b[38;5;120mABC", '<span class="f120">ABC</span>')
        self.assertWhiteBg("\x1b[38;5;120mABC", '<span class="f120">ABC</span>')
        self.assertBlackBg("\x1b[38;5;120;2mABC", '<span class="df120">ABC</span>')
        self.assertWhiteBg("\x1b[38;5;120;2mABC", '<span class="df120">ABC</span>')
        self.assertBlackBg("\x1b[48;5;120mABC", '<span class="b120">ABC</span>')
        self.assertWhiteBg("\x1b[48;5;120mABC", '<span class="b120">ABC</span>')
        self.assertBlackBg("\x1b[48;5;120;2mABC", '<span class="HIK b120">ABC</span>')
        self.assertWhiteBg("\x1b[48;5;120;2mABC", '<span class="HIK b120">ABC</span>')

    # italic, underline, strikethrough
    def test_text_variants(self):
        self.assertBlackBg("\x1b[3mABC", '<span class="ITA">ABC</span>')
        self.assertWhiteBg("\x1b[3mABC", '<span class="ITA">ABC</span>')
        self.assertBlackBg("\x1b[3;31mABC", '<span class="HIR ITA">ABC</span>')
        self.assertWhiteBg("\x1b[3;31mABC", '<span class="HIR ITA">ABC</span>')
        self.assertBlackBg("\x1b[3mAB\x1b[23mC", '<span class="ITA">AB</span>C')
        self.assertWhiteBg("\x1b[3mAB\x1b[23mC", '<span class="ITA">AB</span>C')
        self.assertBlackBg(
            "\x1b[3;31mAB\x1b[23mC",
            '<span class="HIR ITA">AB</span><span class="HIR">C</span>',
        )
        self.assertWhiteBg(
            "\x1b[3;31mAB\x1b[23mC",

            '<span class="HIR ITA">AB</span><span class="HIR">C</span>',