def main():
    """
    $ ls --color=always | ansi2html > directories.html
    $ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
    $ task burndown | ansi2html > burndown.html
    """

    scheme_names = sorted(six.iterkeys(SCHEME))
    version_str = pkg_resources.get_distribution('ansi2html').version
    parser = optparse.OptionParser(
        usage=main.__doc__,
        version="%%prog %s" % version_str)
    parser.add_option(
        "-p", "--partial", dest="partial",
        default=False, action="store_true",
        help="Process lines as them come in.  No headers are produced.")
    parser.add_option(
        "-L", "--latex", dest="latex",
        default=False, action="store_true",
        help="Export as LaTeX instead of HTML.")
    parser.add_option(
        "-i", "--inline", dest="inline",
        default=False, action="store_true",
        help="Inline style without headers or template.")
    parser.add_option(
        "-H", "--headers", dest="headers",
        default=False, action="store_true",
        help="Just produce the <style> tag.")
    parser.add_option(
        "-f", '--font-size', dest='font_size', metavar='SIZE',
        default="normal",
        help="Set the global font size in the output.")
    parser.add_option(
        "-l", '--light-background', dest='light_background',
        default=False, action="store_true",
        help="Set output to 'light background' mode.")
    parser.add_option(
        "-W", '--no-line-wrap', dest='no_line_wrap',
        default=False, action="store_true",
        help="Disable line wrapping.")
    parser.add_option(
        "-a", '--linkify', dest='linkify',
        default=False, action="store_true",
        help="Transform URLs into <a> links.")
    parser.add_option(
        "-u", '--unescape', dest='escaped',
        default=True, action="store_false",
        help="Do not escape XML tags found in the input.")
    parser.add_option(
        "-m", '--markup-lines', dest="markup_lines",
        default=False, action="store_true",
        help="Surround lines with <span id='line-n'>..</span>.")
    parser.add_option(
        '--input-encoding', dest='input_encoding', metavar='ENCODING',
        default='utf-8',
        help="Specify input encoding")
    parser.add_option(
        '--output-encoding', dest='output_encoding', metavar='ENCODING',
        default='utf-8',
        help="Specify output encoding")
    parser.add_option(
        '-s', '--scheme', dest='scheme', metavar='SCHEME',
        default='ansi2html', choices=scheme_names,
        help=("Specify color palette scheme. Default: %%default. Choices: %s"
              % scheme_names))
    parser.add_option(
        '-t', '--title', dest='output_title',
        default='',
        help="Specify output title")

    opts, args = parser.parse_args()

    conv = Ansi2HTMLConverter(
        latex=opts.latex,
        inline=opts.inline,
        dark_bg=not opts.light_background,
        line_wrap=not opts.no_line_wrap,
        font_size=opts.font_size,
        linkify=opts.linkify,
        escaped=opts.escaped,
        markup_lines=opts.markup_lines,
        output_encoding=opts.output_encoding,
        scheme=opts.scheme,
        title=opts.output_title,
    )

    if six.PY3:
        try:
            sys.stdin = io.TextIOWrapper(sys.stdin.detach(), opts.input_encoding, "replace")
        except io.UnsupportedOperation:
            # This only fails in the test suite...
            pass

    def _read(input_bytes):
        if six.PY3:
            return input_bytes
        else:
            return input_bytes.decode(opts.input_encoding)

    def _print(output_unicode, end='\n'):
        if hasattr(sys.stdout, 'buffer'):
            output_bytes = (output_unicode + end).encode(opts.output_encoding)
            sys.stdout.buffer.write(output_bytes)
        elif not six.PY3:
            sys.stdout.write((output_unicode + end).encode(opts.output_encoding))
        else:
            sys.stdout.write(output_unicode + end)

    # Produce only the headers and quit
    if opts.headers:
        _print(conv.produce_headers(), end='')
        return

    full = not bool(opts.partial or opts.inline)
    if six.PY3:
        output = conv.convert("".join(sys.stdin.readlines()), full=full, ensure_trailing_newline=True)
        _print(output, end='')
    else:
        output = conv.convert(six.u("").join(
            map(_read, sys.stdin.readlines())
        ), full=full, ensure_trailing_newline=True)
        _print(output, end='')