Project Name: rsalmei+alive-progress
Language: Python
Statement Type: API

Source Code:
def bar_factory(chars=None, *, tip=None, background=None, borders=None, errors=None):
    """Create a factory of a bar with the given styling parameters.
    Supports unicode grapheme clusters and emoji chars (those that has length one but when on
    screen occupies two cells).

    Now supports transparent fills! Just send a tip, and leave `chars` as None.
    Also tips are now considered for the 100%, which means it smoothly enters and exits the
    frame to get to 100%!! The effect is super cool, use a multi-char tip to see.

    Args:
        chars (Optional[str]): the sequence of increasing glyphs to fill the bar
            can be None for a transparent fill, unless tip is also None.
        tip (Optional[str): the tip in front of the bar
            can be None, unless chars is also None.
        background (Optional[str]): the pattern to be used underneath the bar
        borders (Optional[Union[str, Tuple[str, str]]): the pattern or patterns to be used
            before and after the bar
        errors (Optional[Union[str, Tuple[str, str]]): the pattern or patterns to be used
            when an underflow or overflow occurs

    Returns:
        a styled bar factory

    """

    @bar_controller
    def inner_bar_factory(length, spinner_factory=None):
        if chars:
            if is_wide(chars[-1]):  # previous chars can be anything.
                def fill_style(complete, filling):  # wide chars fill.
                    odd = bool(complete % 2)
                    fill = (None,) if odd != bool(filling) else ()  # odd XOR filling.
                    fill += (chars[-1], None) * int(complete / 2)  # already marked wide chars.
                    if filling and odd:
                        fill += mark_graphemes((chars[filling - 1],))
                    return fill
            else:  # previous chars cannot be wide.
                def fill_style(complete, filling):  # narrow chars fill.
                    fill = (chars[-1],) * complete  # unneeded marks here.
                    if filling:
                        fill += (chars[filling - 1],)  # no widies here.
                    return fill
        else:
            def fill_style(complete, filling):  # invisible fill.
                return fix_cells(padding[:complete + bool(filling)])

        def running(fill):
            return None, (fix_cells(padding[len(fill) + len_tip:]),)  # this is a 1-tuple.

        def ended(fill):
            border = None if len(fill) + len(underflow) <= length else underflow
            texts = *(() if border else (underflow,)), blanks
            return border, texts

        @bordered(borders, '||')
        def draw_known(apply_state, percent):
            virtual_fill = round(virtual_length * max(0., min(1., percent)))
            fill = fill_style(*divmod(virtual_fill, num_graphemes))
            border, texts = apply_state(fill)
            border = overflow if percent > 1. else None if percent == 1. else border
            return fix_cells(combine_cells(fill, tip, *texts)[len_tip:length + len_tip]), border

        if spinner_factory:
            @bordered(borders, '||')
            def draw_unknown(_percent=None):
                return next(player), None

            player = spinner_player(spinner_factory(length))
        else:
            draw_unknown = None

        padding = (' ',) * len_tip + background * math.ceil((length + len_tip) / len(background))
        virtual_length, blanks = num_graphemes * (length + len_tip), (' ',) * length
        return draw_known, running, ended, draw_unknown

    assert chars or tip, 'tip is mandatory for transparent bars'
    assert not (chars and not is_wide(chars[-1]) and has_wide(chars)), \
        'cannot use grapheme with a narrow last char'

    chars = split_graphemes(chars or '')  # the only one not yet marked.
    tip, background = (to_cells(x) for x in (tip, background or ' '))
    underflow, overflow = extract_fill_graphemes(errors, (f'⚠{VS_15}', f'✗{VS_15}'))
    num_graphemes, len_tip = len(chars) or 1, len(tip)
    return inner_bar_factory

bar_factory(chars='▏▎▍▌▋▊▉█', tip=None, background=None, borders=None, errors=None)

Selected Statement: underflow, overflow = extract_fill_graphemes(errors, (f'⚠{VS_15}', f'✗{VS_15}'))

Function Input:
chars: '▏▎▍▌▋▊▉█'
tip: None
background: None
borders: None
errors: None

Variable Values Before Statement:
errors: None

Value After Statement Execution: ('✗︎',)

Variable States During Runtime (line, value):
chars: 1
'▏▎▍▌▋▊▉█'
80
('▏', '▎', '▍', '▌', '▋', '▊', '▉', '█')
tip: 1
None
81
()
background: 1
None
81
(' ',)
borders: 1
None
errors: 1
None
inner_bar_factory: 27
<function bar_controller.<locals>.bar_assembler_factory at 0x7f35540940d0>
overflow: 82
('✗︎',)
underflow: 82
('⚠︎',)
len_tip: 83
0
num_graphemes: 83
8