Exemple #1
0
 def test_ansi_repr(self):
     lb = filled_line_buf()
     l0 = lb.line(0)
     self.ae(l0.as_ansi(), '00000')
     a = []
     lb.as_ansi(a.append)
     self.ae(a, [str(lb.line(i)) + '\n' for i in range(lb.ynum)])
     l2 = lb.line(0)
     c = C()
     c.bold = c.italic = c.reverse = c.strikethrough = c.dim = True
     c.fg = (4 << 8) | 1
     c.bg = (1 << 24) | (2 << 16) | (3 << 8) | 2
     c.decoration_fg = (5 << 8) | 1
     l2.set_text('1', 0, 1, c)
     self.ae(
         l2.as_ansi(), '\x1b[1;2;3;7;9;34;48:2:1:2:3;58:5:5m'
         '1'
         '\x1b[22;23;27;29;39;49;59m'
         '0000')
     lb = filled_line_buf()
     for i in range(lb.ynum):
         lb.set_continued(i, True)
     a = []
     lb.as_ansi(a.append)
     self.ae(a, [str(lb.line(i)) for i in range(lb.ynum)])
     hb = filled_history_buf(5, 5)
     a = []
     hb.as_ansi(a.append)
     self.ae(a,
             [str(hb.line(i)) + '\n' for i in range(hb.count - 1, -1, -1)])
Exemple #2
0
 def test_ansi_repr(self):
     lb = filled_line_buf()
     l = lb.line(0)
     self.ae(l.as_ansi(), '\x1b[0m00000')
     a = []
     lb.as_ansi(a.append)
     self.ae(a, ['\x1b[0m' + str(lb.line(i)) + '\n' for i in range(lb.ynum)])
     l = lb.line(0)
     c = C()
     c.bold = c.italic = c.reverse = c.strikethrough = True
     c.fg = (4 << 8) | 1
     c.bg = (1 << 24) | (2 << 16) | (3 << 8) | 2
     c.decoration_fg = (5 << 8) | 1
     l.set_text('1', 0, 1, c)
     self.ae(l.as_ansi(), '\x1b[0m\x1b[1m\x1b[3m\x1b[7m\x1b[9m\x1b[38;5;4m\x1b[48;2;1;2;3m\x1b[58;5;5m' '1'
             '\x1b[22m\x1b[23m\x1b[27m\x1b[29m\x1b[39m\x1b[49m\x1b[59m' '0000')
     lb = filled_line_buf()
     for i in range(lb.ynum):
         lb.set_continued(i, True)
     a = []
     lb.as_ansi(a.append)
     self.ae(a, ['\x1b[0m' + str(lb.line(i)) for i in range(lb.ynum)])
     hb = filled_history_buf(5, 5)
     a = []
     hb.as_ansi(a.append)
     self.ae(a, ['\x1b[0m' + str(hb.line(i)) + '\n' for i in range(hb.count - 1, -1, -1)])
Exemple #3
0
def create_lbuf(*lines):
    maxw = max(map(len, lines))
    ans = LineBuf(len(lines), maxw)
    prev_full_length = False
    for i, l0 in enumerate(lines):
        ans.line(i).set_text(l0, 0, len(l0), C())
        ans.set_continued(i, prev_full_length)
        prev_full_length = len(l0) == maxw
    return ans
Exemple #4
0
 def create(t):
     lb = create.lb = LineBuf(1, len(t))
     lf = lb.line(0)
     lf.set_text(t, 0, len(t), C())
     return lf
Exemple #5
0
    def test_line(self):
        lb = LineBuf(2, 3)
        for y in range(lb.ynum):
            line = lb.line(y)
            self.ae(str(line), '')
            for x in range(lb.xnum):
                self.ae(line[x], '\0')
        with self.assertRaises(IndexError):
            lb.line(lb.ynum)
        with self.assertRaises(IndexError):
            lb.line(0)[lb.xnum]
        l0 = lb.line(0)
        l0.set_text(' ', 0, len(' '), C())
        l0.add_combining_char(0, '\u0300')
        self.ae(l0[0], ' \u0300')
        l0.add_combining_char(0, '\U000e0100')
        self.ae(l0[0], ' \u0300\U000e0100')
        l0.add_combining_char(0, '\u0302')
        self.ae(l0[0], ' \u0300\u0302')
        self.ae(l0[1], '\0')
        self.ae(str(l0), ' \u0300\u0302')
        t = 'Testing with simple text'
        lb = LineBuf(2, len(t))
        l0 = lb.line(0)
        l0.set_text(t, 0, len(t), C())
        self.ae(str(l0), t)
        l0.set_text('a', 0, 1, C())
        self.assertEqual(str(l0), 'a' + t[1:])

        c = C(3, 5)
        c.bold = c.italic = c.reverse = c.strikethrough = c.dim = True
        c.fg = c.bg = c.decoration_fg = 0x0101
        self.ae(c, c)
        c2, c3 = c.copy(), c.copy()
        self.ae(repr(c), repr(c2))
        self.ae(c, c2)
        c2.bold = False
        self.assertNotEqual(c, c2)
        l0.set_text(t, 0, len(t), C())
        l0.apply_cursor(c2, 3)
        self.assertEqualAttributes(c2, l0.cursor_from(3))
        l0.apply_cursor(c2, 0, len(l0))
        for i in range(len(l0)):
            self.assertEqualAttributes(c2, l0.cursor_from(i))
        l0.apply_cursor(c3, 0)
        self.assertEqualAttributes(c3, l0.cursor_from(0))
        l0.copy_char(0, l0, 1)
        self.assertEqualAttributes(c3, l0.cursor_from(1))

        t = '0123456789'
        lb = LineBuf(1, len(t))
        l3 = lb.line(0)
        l3.set_text(t, 0, len(t), C())
        self.ae(t, str(l3))
        l3.right_shift(4, 2)
        self.ae('0123454567', str(l3))
        l3.set_text(t, 0, len(t), C())
        l3.right_shift(0, 0)
        self.ae(t, str(l3))
        l3.right_shift(0, 1)
        self.ae(str(l3), '0' + t[:-1])
        l3.set_text(t, 0, len(t), C())
        l3.left_shift(0, 2)
        self.ae(str(l3), t[2:] + '89')
        l3.set_text(t, 0, len(t), C())
        l3.left_shift(7, 3)
        self.ae(str(l3), t)

        l3.set_text(t, 0, len(t), C())
        q = C()
        q.bold = q.italic = q.reverse = q.strikethrough = c.dim = True
        q.decoration = 2
        c = C()
        c.x = 3
        l3.set_text('axyb', 1, 2, c)
        self.ae(str(l3), '012xy56789')
        l3.set_char(0, 'x', 1, q)
        self.assertEqualAttributes(l3.cursor_from(0), q)