def show_project_details(data, width):
doc = doc_generator.generate_doc(data, width)
doc = doc.format(
head='\033[0;33m',
project='\033[1;36m',
command='\033[1;33m',
reset='\033[0m'
)
pydoc.pipepager(doc, cmd='less -R')
# pydoc.pager(doc)
python类pipepager()的实例源码
def test_pipepager(self):
# pipepager does not choke on unicode
doc = pydoc.render_doc(self.Q)
saved, os.popen = os.popen, open
try:
with test.test_support.temp_cwd():
pydoc.pipepager(doc, 'pipe')
self.assertEqual(open('pipe').read(), pydoc._encode(doc))
finally:
os.popen = saved
def test_pipepager(self):
# pipepager does not choke on unicode
doc = pydoc.render_doc(self.Q)
saved, os.popen = os.popen, open
try:
with test.test_support.temp_cwd():
pydoc.pipepager(doc, 'pipe')
self.assertEqual(open('pipe').read(), pydoc._encode(doc))
finally:
os.popen = saved
def _page(output, pager_command=None):
"""Conditionally pipes the supplied output through a pager.
:param output:
:type output: object
:param pager_command:
:type pager_command: str
"""
output = six.text_type(output)
if not sys.stdout.isatty() or util.is_windows_platform():
print(output)
sys.stdout.flush()
return
num_lines = output.count('\n')
exceeds_tty_height = pager.getheight() - 1 < num_lines
if pager_command is None:
pager_command = 'less -R'
try:
paginate = config.get_config_val("core.pagination")
except:
paginate = True
if exceeds_tty_height and paginate and \
spawn.find_executable(pager_command.split(' ')[0]) is not None:
pydoc.pipepager(output, cmd=pager_command)
else:
print(output)
def print_results(self, text, result_items):
cprint(text)
if(self.pager):
less_options = "RKIQ"
pydoc.pipepager(text, cmd="less -{0}".format(less_options))
def test_pipepager(self):
# pipepager does not choke on unicode
doc = pydoc.render_doc(self.Q)
saved, os.popen = os.popen, open
try:
with test.test_support.temp_cwd():
pydoc.pipepager(doc, 'pipe')
self.assertEqual(open('pipe').read(), pydoc._encode(doc))
finally:
os.popen = saved
def _page(output, pager_command=None):
"""Conditionally pipes the supplied output through a pager.
:param output:
:type output: object
:param pager_command:
:type pager_command: str
"""
output = six.text_type(output)
if pager_command is None:
pager_command = 'less -R'
if not sys.stdout.isatty() or util.is_windows_platform():
print(output)
return
num_lines = output.count('\n')
exceeds_tty_height = pager.getheight() - 1 < num_lines
paginate = util.get_config().get("core.pagination", True)
if exceeds_tty_height and paginate:
pydoc.pipepager(output, cmd=pager_command)
else:
print(output)