Skip to content

Commit

Permalink
Uses PromptSession() class from prompt_toolkit instead of prompt() fu…
Browse files Browse the repository at this point in the history
…nction (click-contrib#63)

Using the prompt() function from prompt_toolkit.shortcuts led to unbounded memory growth.
We now create a PromptSession() instance and use its prompt() method which takes the same arguments as the the former prompt() function.
  • Loading branch information
srfwx authored Nov 6, 2022
1 parent 1ad52b2 commit 3dc44d9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions click_repl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit import PromptSession
import click
import click.parser
import os
Expand Down Expand Up @@ -186,7 +186,7 @@ def repl( # noqa: C901
:param old_ctx: The current Click context.
:param prompt_kwargs: Parameters passed to
:py:func:`prompt_toolkit.shortcuts.prompt`.
:py:func:`prompt_toolkit.PromptSession`.
If stdin is not a TTY, no prompt will be printed, but only commands read
from stdin.
Expand All @@ -212,11 +212,12 @@ def repl( # noqa: C901
available_commands.pop(repl_command_name, None)

prompt_kwargs = bootstrap_prompt(prompt_kwargs, group)
session = PromptSession(**prompt_kwargs)

if isatty:

def get_command():
return prompt(**prompt_kwargs)
return session.prompt()

else:
get_command = sys.stdin.readline
Expand Down

0 comments on commit 3dc44d9

Please sign in to comment.