How to use the curtsies.formatstringarray.FSArray 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 / 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_oomerror(self):
        a = FSArray(10, 40)
        a[2:-2, 2:-2] = fsarray(['asdf', 'zxcv'])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_no_hanging_space(self):
        a = FSArray(4, 2)
        self.assertEqual(len(a.rows[0]), 0)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_assignment_working(self):
        t = FSArray(10, 10)
        t[2, 2] = 'a'
        t[2, 2] == 'a'
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_len_of_unicode_in_fsarray(self):

        fsa = FSArray(3, 2)
        fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, '┌─', 2)
        self.assertEqual(fsa.shape, (3, 2))
        fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, fmtstr('┌─', 'blue'), 2)
        self.assertEqual(fsa.shape, (3, 2))
github bpython / curtsies / curtsies / formatstringarray.py View on Github external
"""fsarray(list_of_FmtStrs_or_strings, width=None) -> FSArray

    Returns a new FSArray of width of the maximum size of the provided
    strings, or width provided, and height of the number of strings provided.
    If a width is provided, raises a ValueError if any of the strings
    are of length greater than this width"""

    if 'width' in kwargs:
        width = kwargs['width']
        del kwargs['width']
        if strings and max(len(s) for s in strings) > width:
            raise ValueError("Those strings won't fit for width %d" % width)
    else:
        width = max(len(s) for s in strings) if strings else 0
    fstrings = [s if isinstance(s, FmtStr) else fmtstr(s, *args, **kwargs) for s in strings]
    arr = FSArray(len(fstrings), width, *args, **kwargs)
    rows = [fs.setslice_with_length(0, len(s), s, width) for fs, s in zip(arr.rows, fstrings)]
    arr.rows = rows
    return arr
github bpython / curtsies / curtsies / formatstringarray.py View on Github external
def assertFSArraysEqual(self, a, b):
        self.assertEqual(type(a), FSArray)
        self.assertEqual(type(b), FSArray)
        self.assertEqual((a.width, b.height), (a.width, b.height), 'fsarray dimensions do not match: %r %r' % (a.shape, b.shape))
        for i, (a_row, b_row) in enumerate(zip(a, b)):
            self.assertEqual(a_row, b_row, 'FSArrays differ first on line %s:\n%s' % (i, FSArray.diff(a, b)))
github bpython / curtsies / curtsies / formatstringarray.py View on Github external
def assertFSArraysEqual(self, a, b):
        self.assertEqual(type(a), FSArray)
        self.assertEqual(type(b), FSArray)
        self.assertEqual((a.width, b.height), (a.width, b.height), 'fsarray dimensions do not match: %r %r' % (a.shape, b.shape))
        for i, (a_row, b_row) in enumerate(zip(a, b)):
            self.assertEqual(a_row, b_row, 'FSArrays differ first on line %s:\n%s' % (i, FSArray.diff(a, b)))