#!/usr/bin/env python
import argparse

from purdy.cmd import ansi_args, filename_arg, general_args
from purdy.content import Code, Listing
from purdy.scribe import print_ansi, range_set_to_list

# =============================================================================

DESCRIPTION = """This command prints ANSI colourized versions of a file,
parsing the file based on a limited number of pygments lexers. 'pat' is part
of the 'purdy' library. A list of supported lexers is available in the help.
If no lexer is specified the library attempts to determine which lexer to use
automatically.
"""

# =============================================================================
# Main
# =============================================================================

parser = argparse.ArgumentParser(description=DESCRIPTION)
filename_arg(parser)
general_args(parser)
ansi_args(parser)

def main():
    args = parser.parse_args()

    code = Code(lexer_name=args.lexer, filename=args.filename)
    listing = Listing(code, starting_line_number=args.num)

    if args.highlight:
        for num in range_set_to_list(args.highlight):
            listing.set_highlight(True, num, num)

    listing.set_display('ansi')
    print_ansi(listing)

if __name__ == '__main__':
    main()
