MCPcopy
hub / github.com/google/python-fire / More

Function More

fire/console/console_io.py:68–110  ·  view source on GitHub ↗

Run a user specified pager or fall back to the internal pager. Args: contents: The entire contents of the text lines to page. out: The output stream. prompt: The page break prompt. check_pager: Checks the PAGER env var and uses it if True.

(contents, out, prompt=None, check_pager=True)

Source from the content-addressed store, hash-verified

66
67
68def More(contents, out, prompt=None, check_pager=True):
69 """Run a user specified pager or fall back to the internal pager.
70
71 Args:
72 contents: The entire contents of the text lines to page.
73 out: The output stream.
74 prompt: The page break prompt.
75 check_pager: Checks the PAGER env var and uses it if True.
76 """
77 if not IsInteractive(output=True):
78 out.write(contents)
79 return
80 if check_pager:
81 pager = encoding.GetEncodedValue(os.environ, 'PAGER', None)
82 if pager == '-':
83 # Use the fallback Pager.
84 pager = None
85 elif not pager:
86 # Search for a pager that handles ANSI escapes.
87 for command in ('less', 'pager'):
88 if files.FindExecutableOnPath(command):
89 pager = command
90 break
91 if pager:
92 # If the pager is less(1) then instruct it to display raw ANSI escape
93 # sequences to enable colors and font embellishments.
94 less_orig = encoding.GetEncodedValue(os.environ, 'LESS', None)
95 less = '-R' + (less_orig or '')
96 encoding.SetEncodedValue(os.environ, 'LESS', less)
97 # Ignore SIGINT while the pager is running.
98 # We don't want to terminate the parent while the child is still alive.
99 signal.signal(signal.SIGINT, signal.SIG_IGN)
100 p = subprocess.Popen(pager, stdin=subprocess.PIPE, shell=True)
101 enc = console_attr.GetConsoleAttr().GetEncoding()
102 p.communicate(input=contents.encode(enc))
103 p.wait()
104 # Start using default signal handling for SIGINT again.
105 signal.signal(signal.SIGINT, signal.SIG_DFL)
106 if less_orig is None:
107 encoding.SetEncodedValue(os.environ, 'LESS', None)
108 return
109 # Fall back to the internal pager.
110 console_pager.Pager(contents, out, prompt).Run()

Callers

nothing calls this directly

Calls 3

IsInteractiveFunction · 0.85
GetEncodingMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected