From bbba449aa4f039ebc181a28c0563377cd6e93425 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 12 Apr 2014 15:25:42 +0200 Subject: [PATCH] Added some to evtable/evform, seems to work with ansi now. --- src/utils/evform.py | 28 ++++++++++++++++++++++++++++ src/utils/evform_test.py | 6 +++--- src/utils/evtable.py | 21 +++++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/utils/evform.py b/src/utils/evform.py index bf2b106fae..639a983e9f 100644 --- a/src/utils/evform.py +++ b/src/utils/evform.py @@ -413,3 +413,31 @@ class EvForm(object): "prints the form" return unicode(ANSIString("\n").join([line for line in self.form])) +def _test(): + "test evform" + form = EvForm("src.utils.evform_test") + + # add data to each tagged form cell + form.map(cells={1: "{gTom the Bouncer{n", + 2: "{yGriatch{n", + 3: "A sturdy fellow", + 4: 12, + 5: 10, + 6: 5, + 7: 18, + 8: 10, + 9: 3}) + # create the EvTables + tableA = EvTable("HP","MV","MP", + table=[["**"], ["*****"], ["***"]], + border="incols") + tableB = EvTable("Skill", "Value", "Exp", + table=[["Shooting", "Herbalism", "Smithing"], + [12,14,9],["550/1200", "990/1400", "205/900"]], + border="incols") + # add the tables to the proper ids in the form + form.map(tables={"A": tableA, + "B": tableB}) + + # unicode is required since the example contains non-ascii characters + print unicode(form) diff --git a/src/utils/evform_test.py b/src/utils/evform_test.py index 3f1369572a..d2935341aa 100644 --- a/src/utils/evform_test.py +++ b/src/utils/evform_test.py @@ -7,7 +7,7 @@ FORMCHAR = "x" TABLECHAR = "c" FORM = """ -{y.------------------------------------------------. +.------------------------------------------------. | | | Name: xxxxx1xxxxx Player: xxxxxxx2xxxxxxx | | xxxxxxxxxxx | @@ -18,7 +18,7 @@ FORM = """ | xxxxx3xxxxx INT: x6x STA: x7x | | xxxxxxxxxxx LUC: x8x MAG: x9x | | | - {b>----------------------------------------------< + >----------------------------------------------< | | | | cccccccc | ccccccccccccccccccccccccccccccccccc | | cccccccc | ccccccccccccccccccccccccccccccccccc | @@ -26,7 +26,7 @@ FORM = """ | cccccccc | ccccccccccccccccccccccccccccccccccc | | cccccccc | cccccccccccccccccBccccccccccccccccc | | | | -------------------------------------------------- + ------------------------------------------------ """ diff --git a/src/utils/evtable.py b/src/utils/evtable.py index 336d51882c..87e0861f83 100644 --- a/src/utils/evtable.py +++ b/src/utils/evtable.py @@ -69,6 +69,12 @@ to a minimum width and height of 1. It is intended to be used with ANSIString for supporting ANSI-coloured string types. +When a cell is auto-wrapped across multiple lines, +ANSI-reset sequences will be put at the end of each +wrapped line. This means that the colour of a wrapped +cell will not "bleed", but it also means that eventual +colour outside + """ #from textwrap import wrap from textwrap import TextWrapper @@ -406,7 +412,7 @@ class Cell(object): if 0 < width < len(line): # replace_whitespace=False, expand_tabs=False is a # fix for ANSIString not supporting expand_tabs/translate - adjusted_data.extend([ANSIString(part ) + adjusted_data.extend([ANSIString(part + ANSIString("{n")) for part in wrap(line, width=width, drop_whitespace=False)]) else: adjusted_data.append(line) @@ -1124,7 +1130,7 @@ class EvTable(object): self.corner_char = kwargs.get("corner_char", self.corner_char) self.header_line_char = kwargs.get("header_line_char", self.header_line_char) - self.corner_top_left = _to_ansi(kwargs.pop("corner_top_left", self.corner_top_leftorner_char)) + self.corner_top_left = _to_ansi(kwargs.pop("corner_top_left", self.corner_char)) self.corner_top_right = _to_ansi(kwargs.pop("corner_top_right", self.corner_char)) self.corner_bottom_left = _to_ansi(kwargs.pop("corner_bottom_left", self.corner_char)) self.corner_bottom_right = _to_ansi(kwargs.pop("corner_bottom_right", self.corner_char)) @@ -1145,3 +1151,14 @@ class EvTable(object): def __unicode__(self): return unicode(ANSIString("\n").join([line for line in self._generate_lines()])) +def _test(): + "Test" + table = EvTable("{yHeading1{n", "{gHeading2{n", table=[[1,2,3],[4,5,6],[7,8,9]], border="cells") + table.add_column("{rThis is long data{n", "{bThis is even longer data{n") + table.add_row("This is a single row") + print unicode(table) + table.reformat(width=50) + print unicode(table) + + +