<commit_before>"""
Commandline interface for gj2ascii

See `gj2ascii --help` for more info.

$ cat sample-data/polygons.geojson | gj2ascii - \
    sample-data/lines.geojson \
    --bbox sample-data/small-aoi-polygon-line.geojson \
    --width 20 \
    --char ^=red \
    --char -=blue \
    --fill .=green
. . . . . . - . . . . . . . . . ^ ^ ^ ^
. . . . . - . . . . . . . . . . . ^ ^ ^
. . . . - . . . . . . . . . . . . . - -
. . . . - . . . . . . . . - - - - - . ^
^ ^ . - . . . . . . . . . . . . . . . .
^ ^ - . . . . . . . . . . . . . . . . .
^ - ^ . . . . . . . . . . . . . . . . .
^ - . . . . . . . . . . . . . . . . . .
- ^ . . . . . . - . . . . . ^ . . . . .
. - . . . . . . - - . . . ^ ^ . . . . .
. . - . . . . . - . - . ^ ^ ^ . . . . .
. . . - . . . . - . . - ^ ^ ^ . . . . .
. . . . - . . - . . ^ ^ - ^ ^ . . . . .
. . . . . - . - . ^ ^ ^ ^ - ^ . . . . .
. . . . . . - - ^ ^ ^ ^ ^ ^ - . . . . .
"""


import itertools
import os
import random
import string

import gj2ascii
from .pycompat import zip_longest
from .pycompat import string_types

import click
import fiona as fio
try:
    import emoji
except ImportError:
    emoji = None


def _build_colormap(c_map, f_map):

    """
    Combine a character and fill map into a single colormap
    """

    return {k: v for k, v in c_map + f_map if v is not None}


def _cb_char_and_fill(ctx, param, value):

    """
    Click callback to validate --fill and --char.  --char supports multiple
    syntaxes but they cannot be mixed: +, blue, +=blue.

    This whole thing works but needs to be cleaned up.
    """

    # If the user didn't supply anything then value=None
    if value is None:
        value = ()
    elif isinstance(value, string_types):
        value = value,
    else:
        value = value

    output = []
    for val in value:
        if len(val) is 1:
            output.append((val, None))
        elif '=' in val:
            output.append(val.rsplit('=', 1))
        elif len(val) >= 3 and val.startswith(':') and val.endswith(':'):
            output.append('EMOJI-' + val)
            if emoji is None:
                raise click.BadParameter('detect an emoji but could not import the emoji '
                                         'library.  Please `pip install emoji`.')
        else:
            try:<commit_msg>Migrated from emote to emoji.  Closes #26.<commit_after>"""
Commandline interface for gj2ascii

See `gj2ascii --help` for more info.

$ cat sample-data/polygons.geojson | gj2ascii - \
    sample-data/lines.geojson \
    --bbox sample-data/small-aoi-polygon-line.geojson \
    --width 20 \
    --char ^=red \
    --char -=blue \
    --fill .=green
. . . . . . - . . . . . . . . . ^ ^ ^ ^
. . . . . - . . . . . . . . . . . ^ ^ ^
. . . . - . . . . . . . . . . . . . - -
. . . . - . . . . . . . . - - - - - . ^
^ ^ . - . . . . . . . . . . . . . . . .
^ ^ - . . . . . . . . . . . . . . . . .
^ - ^ . . . . . . . . . . . . . . . . .
^ - . . . . . . . . . . . . . . . . . .
- ^ . . . . . . - . . . . . ^ . . . . .
. - . . . . . . - - . . . ^ ^ . . . . .
. . - . . . . . - . - . ^ ^ ^ . . . . .
. . . - . . . . - . . - ^ ^ ^ . . . . .
. . . . - . . - . . ^ ^ - ^ ^ . . . . .
. . . . . - . - . ^ ^ ^ ^ - ^ . . . . .
. . . . . . - - ^ ^ ^ ^ ^ ^ - . . . . .
"""


import itertools
import os
import random
import string

import gj2ascii
from .pycompat import zip_longest
from .pycompat import string_types

import click
import fiona as fio
try:
    import emoji
except ImportError:
    emoji = None


def _build_colormap(c_map, f_map):

    """
    Combine a character and fill map into a single colormap
    """

    return {k: v for k, v in c_map + f_map if v is not None}


def _cb_char_and_fill(ctx, param, value):

    """
    Click callback to validate --fill and --char.  --char supports multiple
    syntaxes but they cannot be mixed: +, blue, +=blue.

    This whole thing works but needs to be cleaned up.
    """

    # If the user didn't supply anything then value=None
    if value is None:
        value = ()
    elif isinstance(value, string_types):
        value = value,
    else:
        value = value

    output = []
    for val in value:
        if len(val) is 1:
            output.append((val, None))
        elif '=' in val:
            output.append(val.rsplit('=', 1))
        elif len(val) >= 3 and val.startswith(':') and val.endswith(':'):
            output.append('EMOJI-' + val)
            if emoji is None:
                raise click.BadParameter('detected an emoji but could not import the emoji '
                                         'library.  Please `pip install emoji`.')
        else:
            try:
{'fraction_non_alphanumeric': 0.20638343756739272, 'fraction_numerical': 0.004313133491481561, 'mean_word_length': 1.085431654676259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 94, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '456112', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1688, 'n_words': 371}