How to use the curtsies.formatstring.fmtstr function in curtsies

To help you get started, we’ve selected a few curtsies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_split(self):
        self.assertEqual(blue('hello there').split(' '), [blue('hello'), blue('there')])
        s = blue('hello there')
        self.assertEqual(s.split(' '), [s[:5], s[6:]])

        # split shouldn't create fmtstrs without chunks
        self.assertEqual(fmtstr('a').split('a')[0].chunks, fmtstr('').chunks)
        self.assertEqual(fmtstr('a').split('a')[1].chunks, fmtstr('').chunks)

        self.assertEqual((fmtstr('imp') + ' ').split('i'), [fmtstr(''), fmtstr('mp') + ' '])
        self.assertEqual(blue('abcbd').split('b'), [blue('a'), blue('c'), blue('d')])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_width_aware_slice(self):
        self.assertEqual(fmtstr('E').width_aware_slice(slice(None, 1, None)).s, ' ')
        self.assertEqual(fmtstr('E').width_aware_slice(slice(None, 2, None)).s, 'E')
        self.assertEqual(fmtstr('HE!', 'blue').width_aware_slice(slice(1, 2, None)), fmtstr(' ', 'blue'))
        self.assertEqual(fmtstr('HE!', 'blue').width_aware_slice(slice(1, 3, None)), fmtstr('E', 'blue'))
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_simple_escapes(self):
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[0m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[39m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[49m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[0m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[32;1mhello')), '\x1b[32m\x1b[1mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[2mhello')), '\x1b[2mhello\x1b[0m')
        self.assertEqual(str(fmtstr('\x1b[32;2mhello')), '\x1b[32m\x1b[2mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[0m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_append_without_atts(self):
        a = fmtstr('no')
        b = a.append('te')
        self.assertEqual(a.s, 'no')
        self.assertEqual(b.s, 'note')
        self.assertEqual(len(b.chunks), 2)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_splice_fmtstr_with_end_with_atts(self):
        # Need to test with fmtstr consisting of multiple chunks
        # and with attributes
        a = fmtstr('notion', 'blue')
        b = a.splice('te', 2, 6)

        self.assertEqual(a.s, "notion")
        self.assertEqual(a.chunks[0].atts, {'fg': 34})
        self.assertEqual(len(a.chunks), 1)

        self.assertEqual(b.s, 'note')
        self.assertEqual(b.chunks[0].atts, {'fg': 34})
        self.assertEqual(b.chunks[1].atts, {})
        self.assertEqual(len(b.chunks), 2)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_simple_escapes(self):
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[0m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[39m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[49m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[0m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[32;1mhello')), '\x1b[32m\x1b[1mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[2mhello')), '\x1b[2mhello\x1b[0m')
        self.assertEqual(str(fmtstr('\x1b[32;2mhello')), '\x1b[32m\x1b[2mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[0m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_shared_atts(self):
        a = fmtstr('hi', 'blue')
        b = fmtstr('there', 'blue')
        c = a + b
        self.assertTrue('fg' in a.shared_atts)
        self.assertTrue('fg' in c.shared_atts)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_simple_escapes(self):
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[0m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[39m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[49m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[0m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[32;1mhello')), '\x1b[32m\x1b[1mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[2mhello')), '\x1b[2mhello\x1b[0m')
        self.assertEqual(str(fmtstr('\x1b[32;2mhello')), '\x1b[32m\x1b[2mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[0m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_new_with_atts_removed(self):
        a = fmtstr('hi', 'blue', 'on_green')
        b = fmtstr('there', 'blue', 'on_red')
        c = a + b
        self.assertEqual(c.new_with_atts_removed('fg'), on_green('hi')+on_red('there'))
github bpython / curtsies / curtsies / fmtfuncs.py View on Github external
from .formatstring import fmtstr

black = _partial(fmtstr, style='black')
red = _partial(fmtstr, style='red')
green = _partial(fmtstr, style='green')
yellow = _partial(fmtstr, style='yellow')
blue = _partial(fmtstr, style='blue')
magenta = _partial(fmtstr, style='magenta')
cyan = _partial(fmtstr, style='cyan')
gray = _partial(fmtstr, style='gray')

on_black = _partial(fmtstr, style='on_black')
on_dark = on_black  # deprecated, old name of on_black
on_red = _partial(fmtstr, style='on_red')
on_green = _partial(fmtstr, style='on_green')
on_yellow = _partial(fmtstr, style='on_yellow')
on_blue = _partial(fmtstr, style='on_blue')
on_magenta = _partial(fmtstr, style='on_magenta')
on_cyan = _partial(fmtstr, style='on_cyan')
on_gray = _partial(fmtstr, style='on_gray')

bold = _partial(fmtstr, style='bold')
dark = _partial(fmtstr, style='dark')
underline = _partial(fmtstr, style='underline')
blink = _partial(fmtstr, style='blink')
invert = _partial(fmtstr, style='invert')

plain = _partial(fmtstr)