"""General helper functions with no Jupyter or pystata dependence"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_misc_utils.ipynb.

# %% auto 0
__all__ = ['Timer', 'print_red']

# %% ../nbs/00_misc_utils.ipynb 3
import time

# %% ../nbs/00_misc_utils.ipynb 4
class Timer():
    text = "Elapsed time: {:0.4f} seconds"
    logger = print
    _start_time = None

    def start(self):
        self._start_time = time.perf_counter()

    def stop(self):
        elapsed_time = time.perf_counter() - self._start_time
        self._start_time = None
        if self.logger:
            self.logger(self.text.format(elapsed_time))

    def __enter__(self):
        self.start()
        return self

    def __exit__(self, *exc_info):
        self.stop()

# %% ../nbs/00_misc_utils.ipynb 6
def print_red(text):
    print(f"\x1b[31m{text}\x1b[0m")
