repl.py 1.0 KB

123456789101112131415161718192021222324252627
  1. """
  2. Tools intended to be used inside a Python REPL, like ipython or python itself.
  3. """
  4. def print_chars(line_length=32, max_char=0x20000):
  5. """Print all chars in the terminal, to help you find that cool one to put in your
  6. customized spinner or bar. Also useful to determine if your terminal do support them.
  7. Args:
  8. line_length (int): the desired characters per line
  9. max_char (int): the last character in the unicode table to show
  10. this goes up to 0x10ffff, but after the default value it seems to return
  11. only question marks, increase it if would like to see more.
  12. """
  13. max_char = min(0x10ffff, max(0, max_char))
  14. for i in range(0x20, max_char + line_length, line_length):
  15. print(f'0x{i:05x}', end=': ')
  16. for j in range(line_length):
  17. if j & 0xf == 0:
  18. print(' ', end='')
  19. try:
  20. print(chr(i + j), end=' ')
  21. except UnicodeEncodeError:
  22. print('?', end=' ')
  23. print()