log.py 490 B

1234567891011121314151617
  1. def to_color(s, c):
  2. return f'\x1b[{c}m{s}\x1b[0m' if use_color else s
  3. def out_line(s='', color=37, indent=0, thread_name=None):
  4. t = ''
  5. if thread_name is not None and show_threads:
  6. t = to_color(f'<{thread_name}> ', thread_color)
  7. print(t + ' ' * indent + to_color(s, color))
  8. def out(s='', color=37, indent=0, thread_name=None):
  9. for line in s.split('\n'):
  10. out_line(line, color, indent, thread_name)
  11. use_color = True
  12. show_threads = True
  13. thread_color = 34