Added m_len to evtable, got it mostly to work with mxp, except for a strange offset of one character (so not yet fully functional)
This commit is contained in:
parent
b50dbdc651
commit
d63db77eb4
1 changed files with 12 additions and 11 deletions
|
|
@ -115,7 +115,7 @@ table string.
|
||||||
#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 evennia.utils.utils import to_unicode
|
from evennia.utils.utils import to_unicode, m_len
|
||||||
from evennia.utils.ansi import ANSIString
|
from evennia.utils.ansi import ANSIString
|
||||||
|
|
||||||
def _to_ansi(obj):
|
def _to_ansi(obj):
|
||||||
|
|
@ -220,7 +220,8 @@ class ANSITextWrapper(TextWrapper):
|
||||||
indent = self.initial_indent
|
indent = self.initial_indent
|
||||||
|
|
||||||
# Maximum width for this line.
|
# Maximum width for this line.
|
||||||
width = self.width - len(indent)
|
width = self.width - m_len(indent)
|
||||||
|
print "width:", width
|
||||||
|
|
||||||
# First chunk on line is whitespace -- drop it, unless this
|
# First chunk on line is whitespace -- drop it, unless this
|
||||||
# is the very beginning of the text (ie. no lines started yet).
|
# is the very beginning of the text (ie. no lines started yet).
|
||||||
|
|
@ -228,7 +229,7 @@ class ANSITextWrapper(TextWrapper):
|
||||||
del chunks[-1]
|
del chunks[-1]
|
||||||
|
|
||||||
while chunks:
|
while chunks:
|
||||||
l = len(chunks[-1])
|
l = m_len(chunks[-1])
|
||||||
|
|
||||||
# Can at least squeeze this chunk onto the current line.
|
# Can at least squeeze this chunk onto the current line.
|
||||||
if cur_len + l <= width:
|
if cur_len + l <= width:
|
||||||
|
|
@ -241,7 +242,7 @@ class ANSITextWrapper(TextWrapper):
|
||||||
|
|
||||||
# The current line is full, and the next chunk is too big to
|
# The current line is full, and the next chunk is too big to
|
||||||
# fit on *any* line (not just this one).
|
# fit on *any* line (not just this one).
|
||||||
if chunks and len(chunks[-1]) > width:
|
if chunks and m_len(chunks[-1]) > width:
|
||||||
self._handle_long_word(chunks, cur_line, cur_len, width)
|
self._handle_long_word(chunks, cur_line, cur_len, width)
|
||||||
|
|
||||||
# If the last chunk on this line is all whitespace, drop it.
|
# If the last chunk on this line is all whitespace, drop it.
|
||||||
|
|
@ -423,7 +424,7 @@ class EvCell(object):
|
||||||
|
|
||||||
#self.data = self._split_lines(unicode(data))
|
#self.data = self._split_lines(unicode(data))
|
||||||
self.data = self._split_lines(_to_ansi(data))
|
self.data = self._split_lines(_to_ansi(data))
|
||||||
self.raw_width = max(len(line) for line in self.data)
|
self.raw_width = max(m_len(line) for line in self.data)
|
||||||
self.raw_height = len(self.data)
|
self.raw_height = len(self.data)
|
||||||
|
|
||||||
# this is extra trimming required for cels in the middle of a table only
|
# this is extra trimming required for cels in the middle of a table only
|
||||||
|
|
@ -458,9 +459,9 @@ class EvCell(object):
|
||||||
width (int): The width to crop `text` to.
|
width (int): The width to crop `text` to.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if len(text) > width:
|
if m_len(text) > width:
|
||||||
crop_string = self.crop_string
|
crop_string = self.crop_string
|
||||||
return text[:width-len(crop_string)] + crop_string
|
return text[:width-m_len(crop_string)] + crop_string
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def _reformat(self):
|
def _reformat(self):
|
||||||
|
|
@ -500,7 +501,7 @@ class EvCell(object):
|
||||||
width = self.width
|
width = self.width
|
||||||
adjusted_data = []
|
adjusted_data = []
|
||||||
for line in data:
|
for line in data:
|
||||||
if 0 < width < len(line):
|
if 0 < width < m_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 + ANSIString("{n"))
|
adjusted_data.extend([ANSIString(part + ANSIString("{n"))
|
||||||
|
|
@ -535,7 +536,7 @@ class EvCell(object):
|
||||||
text (str): Centered text.
|
text (str): Centered text.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
excess = width - len(text)
|
excess = width - m_len(text)
|
||||||
if excess <= 0:
|
if excess <= 0:
|
||||||
return text
|
return text
|
||||||
if excess % 2:
|
if excess % 2:
|
||||||
|
|
@ -695,7 +696,7 @@ class EvCell(object):
|
||||||
natural_width (int): Width of cell.
|
natural_width (int): Width of cell.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return len(self.formatted[0]) #if self.formatted else 0
|
return m_len(self.formatted[0]) #if self.formatted else 0
|
||||||
|
|
||||||
def replace_data(self, data, **kwargs):
|
def replace_data(self, data, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
@ -711,7 +712,7 @@ class EvCell(object):
|
||||||
"""
|
"""
|
||||||
#self.data = self._split_lines(unicode(data))
|
#self.data = self._split_lines(unicode(data))
|
||||||
self.data = self._split_lines(_to_ansi(data))
|
self.data = self._split_lines(_to_ansi(data))
|
||||||
self.raw_width = max(len(line) for line in self.data)
|
self.raw_width = max(m_len(line) for line in self.data)
|
||||||
self.raw_height = len(self.data)
|
self.raw_height = len(self.data)
|
||||||
self.reformat(**kwargs)
|
self.reformat(**kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue