diff options
| author | PikalaxALT <[email protected]> | 2021-01-17 00:15:36 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-17 00:15:36 -0500 |
| commit | b7c7200f4d791bc6bdc74c0f731cd644b60c55b5 (patch) | |
| tree | b3688ad0f8555880d7885861aac60282ef6223b8 /discord/ext/commands/help.py | |
| parent | Fix User public flags not updating (diff) | |
| download | discord.py-b7c7200f4d791bc6bdc74c0f731cd644b60c55b5.tar.xz discord.py-b7c7200f4d791bc6bdc74c0f731cd644b60c55b5.zip | |
[commands] Add linesep kwarg to Paginator
Diffstat (limited to 'discord/ext/commands/help.py')
| -rw-r--r-- | discord/ext/commands/help.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index 82708571..2dd94fcd 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -79,18 +79,22 @@ class Paginator: The suffix appended at the end of every page. e.g. three backticks. max_size: :class:`int` The maximum amount of codepoints allowed in a page. + linesep: :class:`str` + The character string inserted between lines. e.g. a newline character. + .. versionadded:: 1.7 """ - def __init__(self, prefix='```', suffix='```', max_size=2000): + def __init__(self, prefix='```', suffix='```', max_size=2000, linesep='\n'): self.prefix = prefix self.suffix = suffix self.max_size = max_size + self.linesep = linesep self.clear() def clear(self): """Clears the paginator to have no pages.""" if self.prefix is not None: self._current_page = [self.prefix] - self._count = len(self.prefix) + 1 # prefix + newline + self._count = len(self.prefix) + self._linesep_len # prefix + newline else: self._current_page = [] self._count = 0 @@ -104,6 +108,10 @@ class Paginator: def _suffix_len(self): return len(self.suffix) if self.suffix else 0 + @property + def _linesep_len(self): + return len(self.linesep) + def add_line(self, line='', *, empty=False): """Adds a line to the current page. @@ -122,29 +130,29 @@ class Paginator: RuntimeError The line was too big for the current :attr:`max_size`. """ - max_page_size = self.max_size - self._prefix_len - self._suffix_len - 2 + max_page_size = self.max_size - self._prefix_len - self._suffix_len - 2 * self._linesep_len if len(line) > max_page_size: raise RuntimeError('Line exceeds maximum page size %s' % (max_page_size)) - if self._count + len(line) + 1 > self.max_size - self._suffix_len: + if self._count + len(line) + self._linesep_len > self.max_size - self._suffix_len: self.close_page() - self._count += len(line) + 1 + self._count += len(line) + self._linesep_len self._current_page.append(line) if empty: self._current_page.append('') - self._count += 1 + self._count += self._linesep_len def close_page(self): """Prematurely terminate a page.""" if self.suffix is not None: self._current_page.append(self.suffix) - self._pages.append('\n'.join(self._current_page)) + self._pages.append(self.linesep.join(self._current_page)) if self.prefix is not None: self._current_page = [self.prefix] - self._count = len(self.prefix) + 1 # prefix + newline + self._count = len(self.prefix) + self._linesep_len # prefix + linesep else: self._current_page = [] self._count = 0 @@ -162,7 +170,7 @@ class Paginator: return self._pages def __repr__(self): - fmt = '<Paginator prefix: {0.prefix} suffix: {0.suffix} max_size: {0.max_size} count: {0._count}>' + fmt = '<Paginator prefix: {0.prefix!r} suffix: {0.suffix!r} linesep: {0.linesep!r} max_size: {0.max_size} count: {0._count}>' return fmt.format(self) def _not_overriden(f): |