MCPcopy Index your code
hub / github.com/bpython/bpython / page

Function page

bpython/pager.py:47–75  ·  view source on GitHub ↗
(data: str, use_internal: bool = False)

Source from the content-addressed store, hash-verified

45
46
47def 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

Callers

nothing calls this directly

Calls 4

get_pager_commandFunction · 0.85
page_internalFunction · 0.85
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected