added truncate parameter
This commit is contained in:
parent
88d0af40c5
commit
bbee079d2c
@ -260,13 +260,14 @@ class Paginator:
|
||||
def add_page_break(self, *, to_beginning: bool=False) -> None:
|
||||
self.add(self._page_break, to_beginning=to_beginning)
|
||||
|
||||
def add(self, item: typing.Any, *, to_beginning: bool=False, keep_intact: bool=False) -> None:
|
||||
def add(self, item: typing.Any, *, to_beginning: bool=False, keep_intact: bool=False, truncate=False) -> None:
|
||||
item = str(item)
|
||||
i = 0
|
||||
if not keep_intact and not item == self._page_break:
|
||||
item_parts = item.strip('\n').split('\n')
|
||||
for part in item_parts:
|
||||
if len(part) > self._max_line_length:
|
||||
if not truncate:
|
||||
length = 0
|
||||
out_str = ''
|
||||
|
||||
@ -292,6 +293,9 @@ class Paginator:
|
||||
else:
|
||||
close_line(bit)
|
||||
close_line('')
|
||||
else:
|
||||
line = f'{part:.{self._max_line_length-3}}...'
|
||||
self._parts.insert(i, line) if to_beginning else self._parts.append(line)
|
||||
else:
|
||||
self._parts.insert(i, part) if to_beginning else self._parts.append(part)
|
||||
i += 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user