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 = Cursor() 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) ])
def filled_cursor(): ans = Cursor() ans.bold = ans.italic = ans.reverse = ans.strikethrough = True ans.fg = 0x101 ans.bg = 0x201 ans.decoration_fg = 0x301 return ans
def test_char_manipulation(self): s = self.create_screen() def init(): s.reset(), s.reset_dirty() s.draw('abcde') s.cursor.bold = True s.cursor_back(4) s.reset_dirty() self.ae(s.cursor.x, 1) init() s.insert_characters(2) self.ae(str(s.line(0)), 'a bc') self.assertTrue(s.line(0).cursor_from(1).bold) s.cursor_back(1) s.insert_characters(20) self.ae(str(s.line(0)), '') s.draw('xココ') s.cursor_back(5) s.reset_dirty() s.insert_characters(1) self.ae(str(s.line(0)), ' xコ') c = Cursor() c.italic = True s.line(0).apply_cursor(c, 0, 5) self.ae(s.line(0).width(2), 2) self.assertTrue(s.line(0).cursor_from(2).italic) self.assertFalse(s.line(0).cursor_from(2).bold) init() s.delete_characters(2) self.ae(str(s.line(0)), 'ade') self.assertTrue(s.line(0).cursor_from(4).bold) self.assertFalse(s.line(0).cursor_from(2).bold) init() s.erase_characters(2) self.ae(str(s.line(0)), 'a de') self.assertTrue(s.line(0).cursor_from(1).bold) self.assertFalse(s.line(0).cursor_from(4).bold) s.erase_characters(20) self.ae(str(s.line(0)), 'a') init() s.erase_in_line() self.ae(str(s.line(0)), 'a') self.assertTrue(s.line(0).cursor_from(1).bold) self.assertFalse(s.line(0).cursor_from(0).bold) init() s.erase_in_line(1) self.ae(str(s.line(0)), ' cde') init() s.erase_in_line(2) self.ae(str(s.line(0)), '') init() s.erase_in_line(2, True) self.ae((False, False, False, False, False), tuple(map(lambda i: s.line(0).cursor_from(i).bold, range(5))))
def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()): ans = LineBuf(ynum, xnum) cursor.x = 0 for i in range(ynum): t = ('{}'.format(i)) * xnum ans.line(i).set_text(t, 0, xnum, cursor) return ans
def filled_history_buf(ynum=5, xnum=5, cursor=Cursor()): lb = filled_line_buf(ynum, xnum, cursor) ans = HistoryBuf(ynum, xnum) for i in range(ynum): ans.push(lb.line(i)) return ans