Skip to content

Commit

Permalink
Fix 0xacx#127, support Ctrl-C/Ctrl-D
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Jul 14, 2023
1 parent 29ae3a6 commit 6e2cecf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ else
pipe_mode_prompt+=$(cat -)
fi

function handle_ctrl_c {
# newline
echo ""
}
trap handle_ctrl_c INT

while $running; do

if [ -z "$pipe_mode_prompt" ]; then
Expand All @@ -330,7 +336,17 @@ while $running; do
prompt=$(escape "$input_from_temp_file")
else
echo -e "\n${OPENAI_PROMPT:-Enter a prompt:}"
read -e prompt
while true; do
prompt=$(read -e prompt && echo $prompt || exit 1)
# Ctrl-D
if [[ $? == 1 ]]; then
exit
fi
# Ctrl-C
if [ -n "$prompt" ]; then
break
fi
done
fi
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
echo -ne $PROCESSING_LABEL
Expand Down

0 comments on commit 6e2cecf

Please sign in to comment.