diff --git a/alive_progress/core/configuration.py b/alive_progress/core/configuration.py index f7cd613..8a96a4b 100644 --- a/alive_progress/core/configuration.py +++ b/alive_progress/core/configuration.py @@ -137,7 +137,7 @@ def _input(x): Config = namedtuple('Config', 'title length max_cols spinner bar unknown force_tty disable manual ' - 'enrich_print receipt receipt_text monitor elapsed stats ' + 'enrich_print enrich_offset receipt receipt_text monitor elapsed stats ' 'title_length spinner_length refresh_secs monitor_end elapsed_end ' 'stats_end ctrl_c dual_line unit scale precision file') @@ -155,6 +155,7 @@ def reset(): disable=False, manual=False, enrich_print=True, + enrich_offset=0, receipt=True, receipt_text=False, monitor=True, @@ -233,6 +234,7 @@ def lazy_init(): disable=_bool_input_factory(), manual=_bool_input_factory(), enrich_print=_bool_input_factory(), + enrich_offset=_int_input_factory(0, sys.maxsize), receipt=_bool_input_factory(), receipt_text=_bool_input_factory(), monitor=_format_input_factory('count total percent'), diff --git a/alive_progress/core/hook_manager.py b/alive_progress/core/hook_manager.py index dfac2fa..5b43fff 100644 --- a/alive_progress/core/hook_manager.py +++ b/alive_progress/core/hook_manager.py @@ -9,13 +9,14 @@ ENCODING = sys.getdefaultencoding() -def buffered_hook_manager(header_template, get_pos, cond_refresh, term): +def buffered_hook_manager(header_template, get_pos, offset, cond_refresh, term): """Create and maintain a buffered hook manager, used for instrumenting print statements and logging. Args: header_template (): the template for enriching output get_pos (Callable[..., Any]): the container to retrieve the current position + offset (int): the offset to add to the current position cond_refresh: Condition object to force a refresh when printing term: the current terminal @@ -121,7 +122,7 @@ def uninstall(): # internal data. buffers = defaultdict(list) - get_header = gen_header(header_template, get_pos) if header_template else null_header + get_header = gen_header(header_template, get_pos, offset) base = sys.stdout, sys.stderr # needed for tests. before_handlers = {} @@ -154,12 +155,11 @@ def __noop(): # pragma: no cover pass -def gen_header(header_template, get_pos): # pragma: no cover - def inner(): - return header_template.format(get_pos()) +def gen_header(header_template, get_pos, offset): # pragma: no cover + def header(): + return header_template.format(get_pos() + offset) - return inner + def null_header(): + return '' - -def null_header(): # pragma: no cover - return '' + return header if header_template else null_header diff --git a/alive_progress/core/progress.py b/alive_progress/core/progress.py index da0b64c..a0e266a 100644 --- a/alive_progress/core/progress.py +++ b/alive_progress/core/progress.py @@ -89,6 +89,7 @@ def alive_bar(total: Optional[int] = None, *, calibrate: Optional[int] = None, * disable (bool): if True, completely disables all output, do not install hooks manual (bool): set to manually control the bar position enrich_print (bool): enriches print() and logging messages with the bar position + enrich_offset (int): the offset to apply to enrich_print receipt (bool): prints the nice final receipt, disables if False receipt_text (bool): set to repeat the last text message in the final receipt monitor (bool|str): configures the monitor widget `152/200 [76%]` @@ -243,8 +244,8 @@ def pause_monitoring(): term, hook_manager = terminal.get_void(), passthrough_hook_manager() else: term = terminal.get_term(config.file, config.force_tty, config.max_cols) - hook_manager = buffered_hook_manager( - header if config.enrich_print else '', current, cond_refresh, term) + hook_manager = buffered_hook_manager(header if config.enrich_print else '', + current, config.enrich_offset, cond_refresh, term) if term.interactive: thread = threading.Thread(target=run, args=_create_spinner_player(config))