示例#1
0
    def get_pager(self):
        """Create and return a context manager to write to, a pager subprocess if required.

        Returns:
          A context manager.

        """
        if self.is_interactive:
            return pager.ConditionalPager(
                self.vars.get('pager', None),
                minlines=misc_utils.get_screen_height())
        return pager.flush_only(sys.stdout)
示例#2
0
    def get_pager(self):
        """Create and return a context manager to write to, a pager subprocess if required.

        Returns:
          A pair of a file object to write to, and a pipe object to wait on (or
        None if not necessary to wait).
        """
        if self.is_interactive:
            return pager.ConditionalPager(
                self.vars.get('pager', None),
                minlines=misc_utils.get_screen_height())
        file = (codecs.getwriter("utf-8")(sys.stdout.buffer) if hasattr(
            sys.stdout, 'buffer') else sys.stdout)
        return pager.flush_only(file)
示例#3
0
 def test_pager_threshold_above(self):
     with test_utils.capture() as stdout:
         with pager.ConditionalPager('/bin/cat', 20) as file:
             for _ in range(21):
                 file.write('TEST\n')
     self.assertRegex(stdout.getvalue(), 'TEST\nTEST\n')
示例#4
0
 def test_pager_threshold_below(self):
     with test_utils.capture() as stdout:
         with pager.ConditionalPager('/bin/cat', 20) as file:
             file.write('TEST')
     self.assertEqual('TEST', stdout.getvalue())