jupyter.py 747 B

1234567891011121314151617181920212223242526272829
  1. from types import SimpleNamespace
  2. def get_from(parent):
  3. def cols():
  4. # it seems both `jupyter notebook` and `jupyter-lab` do not return cols, only 80 default.
  5. return parent.max_cols
  6. def clear_line():
  7. write(_clear_line)
  8. flush()
  9. def clear_end_line(available=None):
  10. for _ in range(available or 0):
  11. write(' ')
  12. flush()
  13. clear_end_screen = clear_end_line
  14. # it seems spaces are appropriately handled to not wrap lines.
  15. _clear_line = f'\r{" " * cols()}\r'
  16. from .void import factory_cursor_up, hide_cursor, show_cursor # noqa
  17. flush = parent.flush
  18. write = parent.write
  19. carriage_return = parent.carriage_return
  20. return SimpleNamespace(**locals())