Skip to content

Exit on EOF (Ctrl-d) #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2023
Merged

Conversation

MaxGyver83
Copy link
Contributor

Exit on EOF (Ctrl-d)

The exit status of read is 1 in this case. Thus, || break after the read builtin breaks out of the while loop.

Closes #4.

@MaxGyver83
Copy link
Contributor Author

Alternative implementation: Ctrl-d has the same effect as abort inside inline prompts and else the same effect as exit:

diff --git a/TermiC.sh b/TermiC.sh
index 298665b..57f5692 100644
--- a/TermiC.sh
+++ b/TermiC.sh
@@ -32,7 +32,7 @@ echo -e  $initSource > $sourceFile

 while true;do
        [[ $inlineCounter -gt 0 ]] && promptPS1="   " || promptPS1=">> "
-       read -rep "$promptPS1"$(echo $(yes ... | head -n $inlineCounter) | sed 's/ //g') prompt
+       read -rep "$promptPS1"$(echo $(yes ... | head -n $inlineCounter) | sed 's/ //g') prompt || { [[ $inlineCounter -gt 0 ]] && prompt="abort" || break; }
        [[ $prompt == "" ]] && continue
        [[ $prompt == "exit" ]] && break
        [[ $prompt == "clear" ]] && :> $sourceFile && :> $sourceFile.tmp && :> $binaryFile && fullPrompt="" && inlineCounter=0 && echo -e  $initSource > $sourceFile && continue

@hanoglu
Copy link
Owner

hanoglu commented Jun 15, 2023

That sounds good. I also moved read command to a subshell so that when Ctrl + C combination detected, prompt is cleared like Python terminal.

...
trap "echo -e '\nKeyboardInterrupt'" SIGINT
while true;do
	[[ $inlineCounter -gt 0 ]] && promptPS1="   " || promptPS1=">> "
  prompt=$(read -rep "$promptPS1"$(echo $(yes ... | head -n $inlineCounter) | sed 's/ //g') prompt || { [[ $inlineCounter -gt 0 ]] || prompt="exit"; } ; echo $prompt) 
...

@hanoglu hanoglu merged commit 787e7ae into hanoglu:main Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TermiC does not exit after EOF, but exits after receiving a SIGINT
2 participants