(data: str, use_internal: bool = False)
| 45 | |
| 46 | |
| 47 | def page(data: str, use_internal: bool = False) -> None: |
| 48 | command = get_pager_command() |
| 49 | if not command or use_internal: |
| 50 | page_internal(data) |
| 51 | else: |
| 52 | curses.endwin() |
| 53 | try: |
| 54 | popen = subprocess.Popen(command, stdin=subprocess.PIPE) |
| 55 | assert popen.stdin is not None |
| 56 | # `encoding` is new in py39 |
| 57 | data_bytes = data.encode(sys.__stdout__.encoding, "replace") # type: ignore |
| 58 | popen.stdin.write(data_bytes) |
| 59 | popen.stdin.close() |
| 60 | except OSError as e: |
| 61 | if e.errno == errno.ENOENT: |
| 62 | # pager command not found, fall back to internal pager |
| 63 | page_internal(data) |
| 64 | return |
| 65 | if e.errno != errno.EPIPE: |
| 66 | raise |
| 67 | while True: |
| 68 | try: |
| 69 | popen.wait() |
| 70 | except OSError as e: |
| 71 | if e.errno != errno.EINTR: |
| 72 | raise |
| 73 | else: |
| 74 | break |
| 75 | curses.doupdate() |
| 76 | |
| 77 | |
| 78 | # vim: sw=4 ts=4 sts=4 ai et |
nothing calls this directly
no test coverage detected