Added some to evtable/evform, seems to work with ansi now.

This commit is contained in:
Griatch 2014-04-12 15:25:42 +02:00
parent 4a7e332f41
commit bbba449aa4
3 changed files with 50 additions and 5 deletions

View file

@ -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)

View file

@ -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 |
| | |
-------------------------------------------------
------------------------------------------------
"""

View file

@ -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)