rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Fix #151 - Disabled alive_bar crashes when using bar.text with dual_line option #152

Closed jhonatan-lopes closed 2 years ago

jhonatan-lopes commented 2 years ago

Bug #151 was traced back to line 141, inside the set_text function on core.progress:

def set_text(text=None):
        if text and config.dual_line:
            run.text, run.suffix = ('\n', to_cells(str(text))), term.cursor_up_1.sequence

When the bar is disabled, term is set to terminal.VOID (line 204 of same file):

if config.disable:
        term, hook_manager = terminal.VOID, passthrough_hook_manager()

However, when examining terminal.VOID, its factory_cursor_up function doesn't define a sequence attribute as the other terminals do (lines 9 - 15 of utils.terminal.void):

def _ansi_escape_sequence(_=''):
    def inner(_available=None):
        pass

    return inner

which results in the exception being thrown, since term.cursor_up_1 does not have a .sequence attribute.

I've fixed this by simply adding an empty sequence to void's _ansi_escape_sequence:

def _ansi_escape_sequence(_=''):
    def inner(_available=None):
        pass

    inner.sequence = ''
    return inner