def test_no_term(self):
     """
     Raise exception if tigetnum() is called before setupterm()
     """
     jinxed._terminal.TERM = None
     with self.assertRaises(jinxed.error,
                            msg='Must call setupterm() first'):
         jinxed.tigetnum('colors')
Exemplo n.º 2
0
    def number_of_colors(self):
        """
        Read-only property: number of colors supported by terminal.

        Common values are 0, 8, 16, 88, and 256.

        Most commonly, this may be used to test whether the terminal supports
        colors. Though the underlying capability returns -1 when there is no
        color support, we return 0. This lets you test more Pythonically::

            if term.number_of_colors:
                ...
        """
        # This is actually the only remotely useful numeric capability. We
        # don't name it after the underlying capability, because we deviate
        # slightly from its behavior, and we might someday wish to give direct
        # access to it.

        # trim value to 0, as tigetnum('colors') returns -1 if no support,
        # and -2 if no such capability.
        return max(0, self.does_styling and curses.tigetnum('colors') or -1)
 def test_cap_unknown(self):
     """
     Return -1 if capability is unknown
     """
     jinxed.setupterm('xterm')
     self.assertEqual(jinxed.tigetnum('howmuchwoodawoodchuckwillchuck'), -2)
 def test_cap_missing(self):
     """
     Return 0 if capability is missing for terminal
     """
     jinxed.setupterm('xterm')
     self.assertEqual(jinxed.tigetnum('bitwin'), -1)
 def test_cap_present(self):
     """
     Return 1 if capability is present for terminal
     """
     jinxed.setupterm('xterm')
     self.assertEqual(jinxed.tigetnum('colors'), 8)