Skip to content

Commit a315e20

Browse files
committed
Fix 0xacx#127, support Ctrl-C/Ctrl-D
1 parent 926587a commit a315e20

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

chatgpt.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ else
316316
pipe_mode_prompt+=$(cat -)
317317
fi
318318

319+
function handle_ctrl_c {
320+
# newline
321+
echo ""
322+
}
323+
trap handle_ctrl_c INT
324+
319325
while $running; do
320326

321327
if [ -z "$pipe_mode_prompt" ]; then
@@ -326,7 +332,17 @@ while $running; do
326332
prompt=$(escape "$input_from_temp_file")
327333
else
328334
echo -e "\nEnter a prompt:"
329-
read -e prompt
335+
while true; do
336+
prompt=$(read -e prompt && echo $prompt || exit 1)
337+
# Ctrl-D
338+
if [[ $? == 1 ]]; then
339+
exit
340+
fi
341+
# Ctrl-C
342+
if [ -n "$prompt" ]; then
343+
break
344+
fi
345+
done
330346
fi
331347
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
332348
echo -ne $PROCESSING_LABEL

0 commit comments

Comments
 (0)