Skip to content

Commit

Permalink
Fix issue with stdin and --shell option (TheR1D#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Mael Primet <mael.primet@gmail.com>
Co-authored-by: Maximilian Kling <maximilian.b.kling@stud.h-da.de>
  • Loading branch information
3 people authored Jan 13, 2024
1 parent 334580c commit 2503281
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sgpt/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# To allow users to use arrow keys in the REPL.
import os
import readline # noqa: F401
import sys

Expand Down Expand Up @@ -149,6 +150,15 @@ def main(

if stdin_passed and not repl:
prompt = f"{sys.stdin.read()}\n\n{prompt or ''}"
# Switch to stdin for interactive input.
try:
if os.name == "posix":
sys.stdin = open("/dev/tty", "r")
elif os.name == "nt":
sys.stdin = open("CON", "r")
except OSError:
# Non-interactive shell.
pass

if not prompt and not editor and not repl:
raise MissingParameter(param_hint="PROMPT", param_type="string")
Expand Down Expand Up @@ -207,7 +217,7 @@ def main(
functions=function_schemas,
)

while shell and not stdin_passed:
while shell:
option = typer.prompt(
text="[E]xecute, [D]escribe, [A]bort",
type=Choice(("e", "d", "a", "y"), case_sensitive=False),
Expand Down

0 comments on commit 2503281

Please sign in to comment.