From bfa9d7c1ef1232735ae4e6074c246ad636b7ebfc Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Tue, 5 Jun 2018 21:44:13 -0800 Subject: [PATCH] Modify paginator --- exts/imports/utils.py | 18 ++++++++---------- exts/repl.py | 9 ++++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/exts/imports/utils.py b/exts/imports/utils.py index b078e92..d0ff918 100644 --- a/exts/imports/utils.py +++ b/exts/imports/utils.py @@ -66,6 +66,14 @@ def to_list_of_str(items, out: list=list(), level=1, recurse=0): return out +def format_output(text): + if type(text) == list: + text = to_list_of_str(text) + elif type(text) == dict: + text = to_list_of_str(text) + return text + + def replace_text_ignorecase(in_str: str, old: str, new: str='') -> str: re_replace = re.compile(re.escape(old), re.IGNORECASE) return re_replace.sub(f'{new}', in_str) @@ -194,13 +202,3 @@ class Paginator: self._parts.insert(0, item) else: self._parts.append(item) - - -def paginate(text): - paginator = Paginator() - if type(text) == list: - text = to_list_of_str(text) - elif type(text) == dict: - text = to_list_of_str(text) - paginator.add(text) - return paginator.pages() diff --git a/exts/repl.py b/exts/repl.py index 464aab1..81ada50 100644 --- a/exts/repl.py +++ b/exts/repl.py @@ -7,7 +7,7 @@ import inspect import textwrap from contextlib import redirect_stdout import io -from .imports.utils import paginate, run_command +from .imports.utils import run_command, format_output, Paginator ownerids = [351794468870946827, 275280442884751360] ownerid = 351794468870946827 @@ -69,8 +69,11 @@ class Repl: await ctx.message.add_reaction('✅') except Exception: pass - output = f'{value}\nReturned: {ret}' - for page in paginate(output): + value = format_output(value) + pag = Paginator() + pag.add(value) + pag.add(f'\nReturned: {ret}') + for page in pag.pages(): await ctx.send(page) @commands.command(hidden=True)