log.py 621 B

1234567891011121314151617181920212223
  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, newline=True):
  4. t = ''
  5. if thread_name is not None and show_threads:
  6. t = to_color(f'<{thread_name}> ', thread_color)
  7. if newline:
  8. print(t + ' ' * indent + to_color(s, color))
  9. else:
  10. print(t + ' ' * indent + to_color(s, color), end="")
  11. def out(s='', color=37, indent=0, thread_name=None, newline=True):
  12. for line in s.split('\n'):
  13. out_line(line, color, indent, thread_name, newline)
  14. use_color = True
  15. show_threads = True
  16. thread_color = 34