Prepared evtable for changed ANSIString
This commit is contained in:
parent
2edea1eace
commit
44a5a2702d
1 changed files with 11 additions and 7 deletions
|
|
@ -22,7 +22,7 @@ Result:
|
||||||
|
|
||||||
+----------------------+----------+---+--------------------------+
|
+----------------------+----------+---+--------------------------+
|
||||||
| Heading1 | Heading2 | | |
|
| Heading1 | Heading2 | | |
|
||||||
+======================+==========+===+==========================+
|
+~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~+~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~+
|
||||||
| 1 | 4 | 7 | This is long data |
|
| 1 | 4 | 7 | This is long data |
|
||||||
+----------------------+----------+---+--------------------------+
|
+----------------------+----------+---+--------------------------+
|
||||||
| 2 | 5 | 8 | This is even longer data |
|
| 2 | 5 | 8 | This is even longer data |
|
||||||
|
|
@ -43,7 +43,7 @@ table.reformat(width=50, align="l")
|
||||||
creation call) yields the following result:
|
creation call) yields the following result:
|
||||||
+-----------+------------+-----------+-----------+
|
+-----------+------------+-----------+-----------+
|
||||||
| Heading1 | Heading2 | | |
|
| Heading1 | Heading2 | | |
|
||||||
+===========+============+===========+===========+
|
+~~~~~~~~~~~+~~~~~~~~~~~~+~~~~~~~~~~~+~~~~~~~~~~~+
|
||||||
| 1 | 4 | 7 | This is |
|
| 1 | 4 | 7 | This is |
|
||||||
| | | | long data |
|
| | | | long data |
|
||||||
+-----------+------------+-----------+-----------+
|
+-----------+------------+-----------+-----------+
|
||||||
|
|
@ -75,19 +75,19 @@ ANSI-coloured string types.
|
||||||
#from textwrap import wrap
|
#from textwrap import wrap
|
||||||
from textwrap import TextWrapper
|
from textwrap import TextWrapper
|
||||||
from copy import deepcopy, copy
|
from copy import deepcopy, copy
|
||||||
from src.utils.utils import to_unicode
|
from src.utils.utils import to_unicode, to_str
|
||||||
from src.utils.ansi import ANSIString
|
from src.utils.ansi import ANSIString
|
||||||
|
|
||||||
def make_iter(obj):
|
def make_iter(obj):
|
||||||
"Makes sure that the object is always iterable."
|
"Makes sure that the object is always iterable."
|
||||||
return not hasattr(obj, '__iter__') and [obj] or obj
|
return not hasattr(obj, '__iter__') and [obj] or obj
|
||||||
|
|
||||||
def _to_ansi(obj, regexable=False):
|
def _to_ansi(obj):
|
||||||
"convert to ANSIString"
|
"convert to ANSIString"
|
||||||
if hasattr(obj, "__iter__"):
|
if hasattr(obj, "__iter__"):
|
||||||
return [_to_ansi(o) for o in obj]
|
return [_to_ansi(o) for o in obj]
|
||||||
else:
|
else:
|
||||||
return ANSIString(to_unicode(obj), regexable=regexable)
|
return ANSIString(to_unicode(obj))
|
||||||
|
|
||||||
|
|
||||||
_unicode = unicode
|
_unicode = unicode
|
||||||
|
|
@ -133,7 +133,7 @@ class ANSITextWrapper(TextWrapper):
|
||||||
pat = self.wordsep_re_uni
|
pat = self.wordsep_re_uni
|
||||||
else:
|
else:
|
||||||
pat = self.wordsep_simple_re_uni
|
pat = self.wordsep_simple_re_uni
|
||||||
chunks = pat.split(_to_ansi(text, regexable=True))
|
chunks = pat.split(_to_ansi(text))
|
||||||
chunks = filter(None, chunks) # remove empty chunks
|
chunks = filter(None, chunks) # remove empty chunks
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
|
|
@ -408,7 +408,8 @@ class Cell(object):
|
||||||
if 0 < width < len(line):
|
if 0 < width < len(line):
|
||||||
# replace_whitespace=False, expand_tabs=False is a
|
# replace_whitespace=False, expand_tabs=False is a
|
||||||
# fix for ANSIString not supporting expand_tabs/translate
|
# fix for ANSIString not supporting expand_tabs/translate
|
||||||
adjusted_data.extend([ANSIString(part + "{n") for part in wrap(line, width=width, drop_whitespace=False)])
|
adjusted_data.extend([ANSIString(part + "{n")
|
||||||
|
for part in wrap(line, width=width, drop_whitespace=False)])
|
||||||
else:
|
else:
|
||||||
adjusted_data.append(line)
|
adjusted_data.append(line)
|
||||||
if self.enforce_size:
|
if self.enforce_size:
|
||||||
|
|
@ -1138,5 +1139,8 @@ class EvTable(object):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"print table"
|
"print table"
|
||||||
|
return "\n".join([line for line in self._generate_lines()])
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
return to_unicode("\n".join([line for line in self._generate_lines()]))
|
return to_unicode("\n".join([line for line in self._generate_lines()]))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue