diff --git a/eris/termstr.py b/eris/termstr.py index dbb4465..f3c14f8 100644 --- a/eris/termstr.py +++ b/eris/termstr.py @@ -273,15 +273,13 @@ class TermStr(collections.UserString): return self._split_style(self.data.split(sep, maxsplit), len(sep)) def splitlines(self, keepends=0): - lines_with_ends = self.data.splitlines(keepends=True) - lines_without_ends = self.data.splitlines() - result_parts = lines_with_ends if keepends else lines_without_ends result = [] cursor = 0 - for line, line_with_end in zip(result_parts, lines_with_ends): - style_part = self.style[cursor:cursor+len(line)] - result.append(self.__class__(line, style_part)) - cursor += len(line_with_end) + for line in self.data.splitlines(keepends=True): + result_line = line if keepends else line.rstrip("\r\n") + style_part = self.style[cursor:cursor+len(result_line)] + result.append(self.__class__(result_line, style_part)) + cursor += len(line) return result def capitalize(self):