How to use curtsies - 10 common examples

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 / examples / testcache.py View on Github external
from curtsies.fmtfuncs import blue, red, bold, on_red

from curtsies.window import FullscreenWindow

import time

if __name__ == '__main__':

    print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))
    n = int(sys.argv[1]) if len(sys.argv) > 1 else 100

    with FullscreenWindow() as window:
        rows, columns = window.get_term_hw()
        t0 = time.time()
        for i in range(n):
            a = [blue(on_red('qwertyuiop'[i%10]*columns)) for _ in range(rows)]
            window.render_to_terminal(a)
        t1 = time.time()
        t2 = time.time()
        for i in range(n):
            a = [blue(on_red('q'[i%1]*columns)) for _ in range(rows)]
            window.render_to_terminal(a)
        t3 = time.time()
        t4 = time.time()
        a = [blue(on_red('q'*columns)) for _ in range(rows)]
        arrays = []
        for i in range(n):
            a[i // columns] = a[i // columns].setitem(i % columns, 'x')
            arrays.append([fs.copy() for fs in a])
        for i in range(n):
            window.render_to_terminal(arrays[i])
        t5 = time.time()
github bpython / bpython / bpython / curtsiesfrontend / replpainter.py View on Github external
def matches_lines(rows, columns, matches, current, config, match_format):
    highlight_color = func_for_letter(config.color_scheme["operator"].lower())

    if not matches:
        return []
    color = func_for_letter(config.color_scheme["main"])
    max_match_width = max(len(m) for m in matches)
    words_wide = max(1, (columns - 1) // (max_match_width + 1))
    matches = [match_format(m) for m in matches]
    if current:
        current = match_format(current)

    matches = paginate(rows, matches, current, words_wide)

    result = [
        fmtstr(" ").join(
            color(m.ljust(max_match_width))
            if m != current
            else highlight_color(m.ljust(max_match_width))
            for m in matches[i : i + words_wide]
        )
        for i in range(0, len(matches), words_wide)
    ]

    logger.debug("match: %r" % current)
    logger.debug("matches_lines: %r" % result)
    return result
github bpython / bpython / bpython / curtsiesfrontend / replpainter.py View on Github external
def matches_lines(rows, columns, matches, current, config, format):
    highlight_color = func_for_letter(config.color_scheme['operator'].lower())

    if not matches:
        return []
    color = func_for_letter(config.color_scheme['main'])
    max_match_width = max(len(m) for m in matches)
    words_wide = max(1, (columns - 1) // (max_match_width + 1))
    matches = [format(m) for m in matches]
    if current:
        current = format(current)

    matches = paginate(rows, matches, current, words_wide)

    matches_lines = [fmtstr(' ').join(color(m.ljust(max_match_width))
                                      if m != current
                                      else highlight_color(
                                          m.ljust(max_match_width))
                                      for m in matches[i:i + words_wide])
                     for i in range(0, len(matches), words_wide)]

    logger.debug('match: %r' % current)
    logger.debug('matches_lines: %r' % matches_lines)
    return matches_lines
github bpython / curtsies / examples / gameexample.py View on Github external
def __init__(self, width, height):
        self.width = width
        self.height = height
        n = 5
        self.player = Entity(on_blue(green(bold(u'5'))), width // 2, height // 2 - 2, speed=5)
        self.npcs = [Entity(on_blue(red(u'X')), i * width // (n * 2), j * height // (n * 2))
                     for i in range(1, 2*n, 2)
                     for j in range(1, 2*n, 2)]
        self.turn = 0
github bpython / curtsies / examples / gameexample.py View on Github external
def __init__(self, width, height):
        self.width = width
        self.height = height
        n = 5
        self.player = Entity(on_blue(green(bold(u'5'))), width // 2, height // 2 - 2, speed=5)
        self.npcs = [Entity(on_blue(red(u'X')), i * width // (n * 2), j * height // (n * 2))
                     for i in range(1, 2*n, 2)
                     for j in range(1, 2*n, 2)]
        self.turn = 0
github bpython / curtsies / curtsies / window.py View on Github external
def array_from_text_rc(cls, msg, rows, columns):
        arr = FSArray(0, columns)
        i = 0
        for c in msg:
            if i >= rows * columns:
                return arr
            elif c in '\r\n':
                i = ((i // columns) + 1) * columns - 1
            else:
                arr[i // arr.width, i % arr.width] = [fmtstr(c)]
            i += 1
        return arr
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_linessplit(self):
        text = blue('the sum of the squares of the sideways')
        result = [blue('the')+blue(' ')+blue('sum'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('squares'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('sideway'),
                  blue('s')
                  ]
        self.assertEqual(linesplit(text, 7), result)
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_linessplit(self):
        text = blue('the sum of the squares of the sideways')
        result = [blue('the')+blue(' ')+blue('sum'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('squares'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('sideway'),
                  blue('s')
                  ]
        self.assertEqual(linesplit(text, 7), result)