Fix issue with EvTable crop. Resolve #2761
This commit is contained in:
parent
9438e5856a
commit
cc6206db93
2 changed files with 39 additions and 18 deletions
|
|
@ -471,20 +471,6 @@ class EvCell:
|
||||||
else:
|
else:
|
||||||
self.height = self.raw_height
|
self.height = self.raw_height
|
||||||
|
|
||||||
def _crop(self, text, width):
|
|
||||||
"""
|
|
||||||
Apply cropping of text.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
text (str): The text to crop.
|
|
||||||
width (int): The width to crop `text` to.
|
|
||||||
|
|
||||||
"""
|
|
||||||
if d_len(text) > width:
|
|
||||||
crop_string = self.crop_string
|
|
||||||
return text[: width - d_len(crop_string)] + crop_string
|
|
||||||
return text
|
|
||||||
|
|
||||||
def _reformat(self):
|
def _reformat(self):
|
||||||
"""
|
"""
|
||||||
Apply all EvCells' formatting operations.
|
Apply all EvCells' formatting operations.
|
||||||
|
|
@ -541,11 +527,14 @@ class EvCell:
|
||||||
# too many lines. Crop and mark last line with crop_string
|
# too many lines. Crop and mark last line with crop_string
|
||||||
crop_string = self.crop_string
|
crop_string = self.crop_string
|
||||||
adjusted_data = adjusted_data[:-excess]
|
adjusted_data = adjusted_data[:-excess]
|
||||||
|
adjusted_data_length = len(adjusted_data[-1])
|
||||||
crop_string_length = len(crop_string)
|
crop_string_length = len(crop_string)
|
||||||
if len(adjusted_data[-1]) > crop_string_length:
|
if adjusted_data_length >= crop_string_length:
|
||||||
|
# replace with data[...]
|
||||||
|
# (note that if adjusted data is shorter than the crop-string,
|
||||||
|
# we skip the crop-string and just pass the cropped data.)
|
||||||
adjusted_data[-1] = adjusted_data[-1][:-crop_string_length] + crop_string
|
adjusted_data[-1] = adjusted_data[-1][:-crop_string_length] + crop_string
|
||||||
else:
|
|
||||||
adjusted_data[-1] += crop_string
|
|
||||||
elif excess < 0:
|
elif excess < 0:
|
||||||
# too few lines. Fill to height.
|
# too few lines. Fill to height.
|
||||||
adjusted_data.extend(["" for _ in range(excess)])
|
adjusted_data.extend(["" for _ in range(excess)])
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ class TestEvTable(EvenniaTestCase):
|
||||||
|
|
||||||
self._validate(expected, str(table))
|
self._validate(expected, str(table))
|
||||||
|
|
||||||
def test_2762(self):
|
def test_direct_evcolumn_adds(self):
|
||||||
"""
|
"""
|
||||||
Testing https://github.com/evennia/evennia/issues/2762
|
Testing https://github.com/evennia/evennia/issues/2762
|
||||||
|
|
||||||
|
|
@ -276,3 +276,35 @@ class TestEvTable(EvenniaTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._validate(expected, str(table))
|
self._validate(expected, str(table))
|
||||||
|
|
||||||
|
def test_width_enforcement(self):
|
||||||
|
"""
|
||||||
|
Testing https://github.com/evennia/evennia/issues/2761
|
||||||
|
|
||||||
|
EvTable enforces width kwarg, expanding the wrong column
|
||||||
|
|
||||||
|
"""
|
||||||
|
# simple crop
|
||||||
|
table = evtable.EvTable(table=[["column"]], width=7, enforce_size=True)
|
||||||
|
expected = """
|
||||||
|
+-----+
|
||||||
|
| col |
|
||||||
|
+-----+
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._validate(expected, str(table))
|
||||||
|
|
||||||
|
colA = evtable.EvColumn("it", "is", "a", "column", width=6, enforce_size=True)
|
||||||
|
colB = evtable.EvColumn("and", "another", "column", "here")
|
||||||
|
table = evtable.EvTable(table=[colA, colB], width=40)
|
||||||
|
|
||||||
|
expected = """
|
||||||
|
+----+---------------------------------+
|
||||||
|
| it | and |
|
||||||
|
| is | another |
|
||||||
|
| a | column |
|
||||||
|
| co | here |
|
||||||
|
+----+---------------------------------+
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._validate(expected, str(table))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue