Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ipython_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
from collections import defaultdict
from threading import Thread
from inspect import isclass
import token
from pygments import token

from IPython.utils import PyColorize
from IPython import get_ipython
from IPython.display import display
from IPython.core.magic import register_line_magic
from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring

Expand Down Expand Up @@ -179,7 +178,7 @@ def findsymbol(arg):
sys.stdout._raw = True
except AttributeError:
pass
cs = PyColorize.Parser().color_table[shell.colors].colors
cs = PyColorize.theme_table[shell.colors]
print(
"{}Suggestions:{} {}".format(cs[token.NUMBER], cs["normal"], line)
)
Expand All @@ -204,6 +203,11 @@ def findsymbol(arg):
def suggestion(arg):
global _symbols_last
args = parse_argstring(suggestion, arg)

if not _symbols_last:
print("No suggestions available.")
return

if -len(_symbols_last) < args.suggestion_index < len(_symbols_last):
method, line = _symbols_last[args.suggestion_index]
if method == "exec":
Expand All @@ -213,9 +217,10 @@ def suggestion(arg):
sys.stdout._raw = True
except AttributeError:
pass
cs = PyColorize.Parser().color_table[shell.colors].colors
print(
"{}Suggestions:{} {}".format(cs[token.NUMBER], cs["normal"], line)
PyColorize.theme_table[shell.colors].format(
[(token.Number, f"Suggestions: {line}")]
)
)

shell.execution_count += 1
Expand Down